import Rewind from "~/components/rewind/Rewind"; import type { Route } from "./+types/Home"; import { type RewindStats } from "api/api"; import { useState } from "react"; import type { LoaderFunctionArgs } from "react-router"; import { useLoaderData } from "react-router"; import { getRewindYear } from "~/utils/utils"; export async function clientLoader({ request }: LoaderFunctionArgs) { const url = new URL(request.url); const year = url.searchParams.get("year") || getRewindYear(); const res = await fetch(`/apis/web/v1/summary?year=${year}`); if (!res.ok) { throw new Response("Failed to load summary", { status: 500 }); } const stats: RewindStats = await res.json(); stats.title = `Your ${year} Rewind`; return { stats }; } export function meta({}: Route.MetaArgs) { return [ { title: `Rewind - Koito` }, { name: "description", content: "Rewind - Koito" }, ]; } export default function RewindPage() { const [showTime, setShowTime] = useState(false); const { stats: stats } = useLoaderData<{ stats: RewindStats }>(); return (
{stats.title} - Koito
setShowTime(!showTime)} >
{stats !== undefined && }
); }