diff --git a/client/app/components/sidebar/Sidebar.tsx b/client/app/components/sidebar/Sidebar.tsx index 31a59e0..434b99a 100644 --- a/client/app/components/sidebar/Sidebar.tsx +++ b/client/app/components/sidebar/Sidebar.tsx @@ -45,7 +45,9 @@ export default function Sidebar() { {}} modal={<>} diff --git a/client/app/routes/RewindPage.tsx b/client/app/routes/RewindPage.tsx index 2d60697..1c1727e 100644 --- a/client/app/routes/RewindPage.tsx +++ b/client/app/routes/RewindPage.tsx @@ -4,7 +4,7 @@ import { imageUrl, type RewindStats } from "api/api"; import { useEffect, useState } from "react"; import type { LoaderFunctionArgs } from "react-router"; import { useLoaderData } from "react-router"; -import { getRewindYear } from "~/utils/utils"; +import { getRewindParams, getRewindYear } from "~/utils/utils"; import { useNavigate } from "react-router"; import { average } from "color.js"; import { ChevronLeft, ChevronRight } from "lucide-react"; @@ -29,8 +29,10 @@ const months = [ export async function clientLoader({ request }: LoaderFunctionArgs) { const url = new URL(request.url); - const year = parseInt(url.searchParams.get("year") || "0") || getRewindYear(); - const month = parseInt(url.searchParams.get("month") || "0"); + const year = + parseInt(url.searchParams.get("year") || "0") || getRewindParams().year; + const month = + parseInt(url.searchParams.get("month") || "0") || getRewindParams().month; const res = await fetch(`/apis/web/v1/summary?year=${year}&month=${month}`); if (!res.ok) { diff --git a/client/app/utils/utils.ts b/client/app/utils/utils.ts index 79d9bc9..4acbad5 100644 --- a/client/app/utils/utils.ts +++ b/client/app/utils/utils.ts @@ -19,12 +19,12 @@ const getRewindYear = (): number => { return new Date().getFullYear() - 1; }; -const getRewindParams = (): string => { +const getRewindParams = (): { month: number; year: number } => { const today = new Date(); if (today.getMonth() == 0) { - return `year=${today.getFullYear() - 1}`; + return { month: 0, year: today.getFullYear() - 1 }; } else { - return `month=${today.getMonth()}`; + return { month: today.getMonth(), year: today.getFullYear() }; } };