mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 20:11:50 -07:00
fix rewind default page
This commit is contained in:
parent
9678117c05
commit
925c308552
3 changed files with 11 additions and 7 deletions
|
|
@ -45,7 +45,9 @@ export default function Sidebar() {
|
|||
<SidebarSearch size={iconSize} />
|
||||
<SidebarItem
|
||||
space={10}
|
||||
to={`/rewind?${getRewindParams()}`}
|
||||
to={`/rewind?year=${getRewindParams().year}&month=${
|
||||
getRewindParams().month
|
||||
}`}
|
||||
name="Rewind"
|
||||
onClick={() => {}}
|
||||
modal={<></>}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() };
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue