mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 20:11:50 -07:00
param fixes
This commit is contained in:
parent
b0b0284a3d
commit
f8eedeb6ef
3 changed files with 17 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ import { ExternalLink, History, Home, Info } from "lucide-react";
|
||||||
import SidebarSearch from "./SidebarSearch";
|
import SidebarSearch from "./SidebarSearch";
|
||||||
import SidebarItem from "./SidebarItem";
|
import SidebarItem from "./SidebarItem";
|
||||||
import SidebarSettings from "./SidebarSettings";
|
import SidebarSettings from "./SidebarSettings";
|
||||||
|
import { getRewindYear } from "~/utils/utils";
|
||||||
|
|
||||||
export default function Sidebar() {
|
export default function Sidebar() {
|
||||||
const iconSize = 20;
|
const iconSize = 20;
|
||||||
|
|
@ -44,7 +45,7 @@ export default function Sidebar() {
|
||||||
<SidebarSearch size={iconSize} />
|
<SidebarSearch size={iconSize} />
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
space={10}
|
space={10}
|
||||||
to={`/rewind?year=${new Date().getFullYear()}`}
|
to={`/rewind?year=${getRewindYear()}`}
|
||||||
name="Rewind"
|
name="Rewind"
|
||||||
onClick={() => {}}
|
onClick={() => {}}
|
||||||
modal={<></>}
|
modal={<></>}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import Rewind from "~/components/rewind/Rewind";
|
import Rewind from "~/components/rewind/Rewind";
|
||||||
import type { Route } from "./+types/Home";
|
import type { Route } from "./+types/Home";
|
||||||
import { getRewindStats, type RewindStats } from "api/api";
|
import { type RewindStats } from "api/api";
|
||||||
import { useEffect, useState } from "react";
|
import { 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";
|
||||||
|
|
||||||
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 = url.searchParams.get("year") || new Date().getFullYear();
|
const year = url.searchParams.get("year") || getRewindYear();
|
||||||
|
|
||||||
const res = await fetch(`/apis/web/v1/summary?year=${year}`);
|
const res = await fetch(`/apis/web/v1/summary?year=${year}`);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,16 @@ const timeframeToInterval = (timeframe: Timeframe): string => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getRewindYear = (): number => {
|
||||||
|
const today = new Date();
|
||||||
|
if (today.getMonth() > 10 && today.getDate() >= 30) {
|
||||||
|
// if we are in december 30/31, just serve current year
|
||||||
|
return today.getFullYear();
|
||||||
|
} else {
|
||||||
|
return today.getFullYear() - 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function timeSince(date: Date) {
|
function timeSince(date: Date) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||||
|
|
@ -104,5 +114,5 @@ const timeListenedString = (seconds: number) => {
|
||||||
return `${minutes} minutes listened`;
|
return `${minutes} minutes listened`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hexToHSL, timeListenedString };
|
export { hexToHSL, timeListenedString, getRewindYear };
|
||||||
export type { hsl };
|
export type { hsl };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue