Files
josh 6447db3008
Build and Deploy / Build & Push (push) Successful in 1m7s
refactor: store selected week in a cookie, not the URL
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>
2026-05-30 08:39:20 -04:00

30 lines
845 B
TypeScript

"use server";
import { cookies } from "next/headers";
import { revalidatePath } from "next/cache";
const WEEK_COOKIE = "tcWeek";
const MAX_AGE = 60 * 60 * 24 * 30; // 30 days
/**
* Persist the selected week start (YYYY-MM-DD) in a server-readable cookie
* and revalidate the home page so the new week renders.
*/
export async function setWeek(weekStart: string): Promise<void> {
if (!/^\d{4}-\d{2}-\d{2}$/.test(weekStart)) return;
const cookieStore = await cookies();
cookieStore.set(WEEK_COOKIE, weekStart, {
path: "/",
maxAge: MAX_AGE,
sameSite: "lax",
});
revalidatePath("/");
}
/** Clear the saved week — used by the "Today" button to jump back to current. */
export async function clearWeek(): Promise<void> {
const cookieStore = await cookies();
cookieStore.delete(WEEK_COOKIE);
revalidatePath("/");
}