From b0b0284a3d42721a6b91d28eed7fdecb3b033187 Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Wed, 31 Dec 2025 18:28:44 -0500 Subject: [PATCH] fix layout, year param --- client/app/components/rewind/Rewind.tsx | 2 +- client/app/components/sidebar/Sidebar.tsx | 2 +- client/app/routes/RewindPage.tsx | 54 ++++++++++++++++------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/client/app/components/rewind/Rewind.tsx b/client/app/components/rewind/Rewind.tsx index 21878c5..e45ee2a 100644 --- a/client/app/components/rewind/Rewind.tsx +++ b/client/app/components/rewind/Rewind.tsx @@ -13,7 +13,7 @@ export default function Rewind(props: Props) { const trackimg = props.stats.top_tracks[0].image; return (
-

{props.stats.title}

+

{props.stats.title}

{}} modal={<>} diff --git a/client/app/routes/RewindPage.tsx b/client/app/routes/RewindPage.tsx index 0aae61a..1951caa 100644 --- a/client/app/routes/RewindPage.tsx +++ b/client/app/routes/RewindPage.tsx @@ -2,30 +2,50 @@ import Rewind from "~/components/rewind/Rewind"; import type { Route } from "./+types/Home"; import { getRewindStats, type RewindStats } from "api/api"; import { useEffect, useState } from "react"; +import type { LoaderFunctionArgs } from "react-router"; +import { useLoaderData } from "react-router"; + +export async function clientLoader({ request }: LoaderFunctionArgs) { + const url = new URL(request.url); + const year = url.searchParams.get("year") || new Date().getFullYear(); + + 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: "Koito" }, { name: "description", content: "Koito" }]; + return [ + { title: `Rewind - Koito` }, + { name: "description", content: "Rewind - Koito" }, + ]; } export default function RewindPage() { - const [stats, setStats] = useState(undefined); const [showTime, setShowTime] = useState(false); - useEffect(() => { - getRewindStats({ year: 2025 }).then((r) => setStats(r)); - }, []); + const { stats: stats } = useLoaderData<{ stats: RewindStats }>(); return ( -
-
- - setShowTime(!showTime)} - > +
+ {stats.title} - Koito + + +
+
+ + setShowTime(!showTime)} + > +
+ {stats !== undefined && }
-

Your 2025 Rewind

- {stats !== undefined && } -
+ ); }