fix rewind default page

This commit is contained in:
Gabe Farrell 2026-01-12 23:08:31 -05:00
parent 9678117c05
commit 925c308552
3 changed files with 11 additions and 7 deletions

View file

@ -45,7 +45,9 @@ export default function Sidebar() {
<SidebarSearch size={iconSize} /> <SidebarSearch size={iconSize} />
<SidebarItem <SidebarItem
space={10} space={10}
to={`/rewind?${getRewindParams()}`} to={`/rewind?year=${getRewindParams().year}&month=${
getRewindParams().month
}`}
name="Rewind" name="Rewind"
onClick={() => {}} onClick={() => {}}
modal={<></>} modal={<></>}

View file

@ -4,7 +4,7 @@ import { imageUrl, type RewindStats } from "api/api";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { LoaderFunctionArgs } from "react-router"; import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData } 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 { useNavigate } from "react-router";
import { average } from "color.js"; import { average } from "color.js";
import { ChevronLeft, ChevronRight } from "lucide-react"; import { ChevronLeft, ChevronRight } from "lucide-react";
@ -29,8 +29,10 @@ const months = [
export async function clientLoader({ request }: LoaderFunctionArgs) { export async function clientLoader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url); const url = new URL(request.url);
const year = parseInt(url.searchParams.get("year") || "0") || getRewindYear(); const year =
const month = parseInt(url.searchParams.get("month") || "0"); 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}`); const res = await fetch(`/apis/web/v1/summary?year=${year}&month=${month}`);
if (!res.ok) { if (!res.ok) {

View file

@ -19,12 +19,12 @@ const getRewindYear = (): number => {
return new Date().getFullYear() - 1; return new Date().getFullYear() - 1;
}; };
const getRewindParams = (): string => { const getRewindParams = (): { month: number; year: number } => {
const today = new Date(); const today = new Date();
if (today.getMonth() == 0) { if (today.getMonth() == 0) {
return `year=${today.getFullYear() - 1}`; return { month: 0, year: today.getFullYear() - 1 };
} else { } else {
return `month=${today.getMonth()}`; return { month: today.getMonth(), year: today.getFullYear() };
} }
}; };