src/pages/cellar/index.astro 1.1 K raw
1
---
2
export const prerender = false;
3
4
import PageLayout from "@/layouts/Base.astro";
5
import WineCard from "@/components/page/WineCard.astro";
6
7
const meta = {
8
	title: "/cellar",
9
	description: "My wine tasting log",
10
};
11
12
const CELLAR_API_URL =
13
	import.meta.env.CELLAR_API_URL ?? "https://cellar.stevedylan.dev";
14
15
let wines: any[] = [];
16
let error: string | null = null;
17
try {
18
	const res = await fetch(`${CELLAR_API_URL}/api/wines`);
19
	if (res.ok) {
20
		wines = await res.json();
21
	} else {
22
		error = `API returned ${res.status}`;
23
	}
24
} catch (e) {
25
	error = e instanceof Error ? e.message : "Failed to reach cellar API";
26
}
27
---
28
29
<PageLayout meta={meta}>
30
	<div class="flex min-h-screen flex-col items-start justify-start gap-6">
31
    <h1 class="title">/cellar</h1>
32
		{error ? (
33
			<p class="text-red-400 text-sm">Could not load wines: {error}</p>
34
		) : wines.length === 0 ? (
35
			<p class="text-zinc-400 text-sm">no wines yet</p>
36
		) : (
37
			<div class="flex flex-col w-full">
38
				{wines.map((wine: any) => (
39
					<WineCard wine={wine} cellarApiUrl={CELLAR_API_URL} />
40
				))}
41
			</div>
42
		)}
43
	</div>
44
</PageLayout>