mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 12:01:52 -07:00
fix layout, year param
This commit is contained in:
parent
60667ea716
commit
b0b0284a3d
3 changed files with 39 additions and 19 deletions
|
|
@ -13,7 +13,7 @@ export default function Rewind(props: Props) {
|
||||||
const trackimg = props.stats.top_tracks[0].image;
|
const trackimg = props.stats.top_tracks[0].image;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-7">
|
<div className="flex flex-col gap-7">
|
||||||
<h1>{props.stats.title}</h1>
|
<h2>{props.stats.title}</h2>
|
||||||
<RewindTopItem
|
<RewindTopItem
|
||||||
title="Top Artist"
|
title="Top Artist"
|
||||||
imageSrc={imageUrl(artistimg, "medium")}
|
imageSrc={imageUrl(artistimg, "medium")}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ export default function Sidebar() {
|
||||||
<SidebarSearch size={iconSize} />
|
<SidebarSearch size={iconSize} />
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
space={10}
|
space={10}
|
||||||
to="/rewind"
|
to={`/rewind?year=${new Date().getFullYear()}`}
|
||||||
name="Rewind"
|
name="Rewind"
|
||||||
onClick={() => {}}
|
onClick={() => {}}
|
||||||
modal={<></>}
|
modal={<></>}
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,39 @@ 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 { getRewindStats, type RewindStats } from "api/api";
|
||||||
import { useEffect, useState } from "react";
|
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) {
|
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() {
|
export default function RewindPage() {
|
||||||
const [stats, setStats] = useState<RewindStats | undefined>(undefined);
|
|
||||||
const [showTime, setShowTime] = useState(false);
|
const [showTime, setShowTime] = useState(false);
|
||||||
useEffect(() => {
|
const { stats: stats } = useLoaderData<{ stats: RewindStats }>();
|
||||||
getRewindStats({ year: 2025 }).then((r) => setStats(r));
|
|
||||||
}, []);
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-start mt-20">
|
<main className="w-18/20">
|
||||||
|
<title>{stats.title} - Koito</title>
|
||||||
|
<meta property="og:title" content={`${stats.title} - Koito`} />
|
||||||
|
<meta name="description" content={`${stats.title} - Koito`} />
|
||||||
|
<div className="flex flex-col items-start mt-20 gap-10">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<label htmlFor="show-time-checkbox">Show time listened?</label>
|
<label htmlFor="show-time-checkbox">Show time listened?</label>
|
||||||
<input
|
<input
|
||||||
|
|
@ -24,8 +44,8 @@ export default function RewindPage() {
|
||||||
onChange={(e) => setShowTime(!showTime)}
|
onChange={(e) => setShowTime(!showTime)}
|
||||||
></input>
|
></input>
|
||||||
</div>
|
</div>
|
||||||
<h2 className="mt-12">Your 2025 Rewind</h2>
|
|
||||||
{stats !== undefined && <Rewind stats={stats} includeTime={showTime} />}
|
{stats !== undefined && <Rewind stats={stats} includeTime={showTime} />}
|
||||||
</div>
|
</div>
|
||||||
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue