6447db3008
Build and Deploy / Build & Push (push) Successful in 1m7s
The home page no longer reads ?week=YYYY-MM-DD from the URL. Selected week lives in the tcWeek cookie, set via a server action that revalidates the home page so the next render reflects it. The URL stays at "/" regardless of which week the user is viewing. WeekNav prev/next/today buttons (and the arrow-key bindings) call the server action directly — no router.refresh dance, no client-side cookie write. BackToCalendarLink drops its localStorage-based href reconstruction and just links to "/" since the cookie already remembers the right week across navigations. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { HomePageClient } from "@/components/HomePageClient";
|
|
import { getTodayLocal, formatDateLocal } from "@/lib/env";
|
|
|
|
const BACKEND_URL = process.env.BACKEND_URL ?? "http://localhost:3001";
|
|
|
|
const WEEK_COOKIE = "tcWeek";
|
|
|
|
function getWeekStart(saved: string | undefined): string {
|
|
if (saved && /^\d{4}-\d{2}-\d{2}$/.test(saved)) {
|
|
const d = new Date(saved + "T00:00:00");
|
|
if (!isNaN(d.getTime())) {
|
|
d.setDate(d.getDate() - d.getDay());
|
|
return formatDateLocal(d);
|
|
}
|
|
}
|
|
const todayIso = getTodayLocal();
|
|
const d = new Date(todayIso + "T00:00:00");
|
|
d.setDate(d.getDate() - d.getDay());
|
|
return formatDateLocal(d);
|
|
}
|
|
|
|
export default async function HomePage() {
|
|
const saved = (await cookies()).get(WEEK_COOKIE)?.value;
|
|
const weekStart = getWeekStart(saved);
|
|
|
|
const data = await fetch(
|
|
`${BACKEND_URL}/api/calendar/week?start=${weekStart}`,
|
|
{ next: { revalidate: 120 } },
|
|
).then((r) => r.json());
|
|
|
|
return <HomePageClient {...data} />;
|
|
}
|