3815da2d3f
Server components now fetch composed data from the backend instead of directly querying SQLite and external APIs. Removes better-sqlite3 dependency from the frontend entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { HomePageClient } from "@/components/HomePageClient";
|
|
import { getTodayLocal } from "@/lib/env";
|
|
|
|
const BACKEND_URL = process.env.BACKEND_URL ?? "http://localhost:3001";
|
|
|
|
interface PageProps {
|
|
searchParams: Promise<{ week?: string }>;
|
|
}
|
|
|
|
function getWeekStart(param: string | undefined): string {
|
|
if (param && /^\d{4}-\d{2}-\d{2}$/.test(param)) {
|
|
const d = new Date(param + "T00:00:00");
|
|
if (!isNaN(d.getTime())) {
|
|
d.setDate(d.getDate() - d.getDay());
|
|
return d.toISOString().slice(0, 10);
|
|
}
|
|
}
|
|
const todayIso = getTodayLocal();
|
|
const d = new Date(todayIso + "T00:00:00");
|
|
d.setDate(d.getDate() - d.getDay());
|
|
return d.toISOString().slice(0, 10);
|
|
}
|
|
|
|
export default async function HomePage({ searchParams }: PageProps) {
|
|
const params = await searchParams;
|
|
const weekStart = getWeekStart(params.week);
|
|
|
|
const data = await fetch(
|
|
`${BACKEND_URL}/api/calendar/week?start=${weekStart}`,
|
|
{ next: { revalidate: 120 } },
|
|
).then((r) => r.json());
|
|
|
|
return <HomePageClient {...data} />;
|
|
}
|