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 && }
-
+
);
}