diff --git a/client/app/app.css b/client/app/app.css index e43f0e4..217e955 100644 --- a/client/app/app.css +++ b/client/app/app.css @@ -63,7 +63,7 @@ @media (min-width: 60rem) { :root { --header-xl: 78px; - --header-lg: 44px; + --header-lg: 36px; --header-md: 22px; --header-sm: 16px; --header-xl-weight: 600; diff --git a/client/app/components/rewind/Rewind.tsx b/client/app/components/rewind/Rewind.tsx index 6ec127f..45b32db 100644 --- a/client/app/components/rewind/Rewind.tsx +++ b/client/app/components/rewind/Rewind.tsx @@ -1,9 +1,10 @@ import { imageUrl, type RewindStats } from "api/api"; -import RewindTopItem from "./RewindTopItem"; +import RewindStatText from "./RewindStatText"; +import { RewindTopItem } from "./RewindTopItem"; interface Props { stats: RewindStats; - includeTime: boolean; + includeTime?: boolean; } export default function Rewind(props: Props) { @@ -11,103 +12,60 @@ export default function Rewind(props: Props) { const albumimg = props.stats.top_albums[0].image; const trackimg = props.stats.top_tracks[0].image; return ( -
+

{props.stats.title}

-
-
- -
-
-

Top Artist

-
-
-

{props.stats.top_artists[0].name}

- - {`${props.stats.top_artists[0].listen_count} plays`} - {props.includeTime - ? ` (${Math.floor( - props.stats.top_artists[0].time_listened / 60 - )} minutes)` - : ``} - -
-
- {props.stats.top_artists.slice(1).map((e, i) => ( -
- {e.name} - - {` - ${e.listen_count} plays`} - {props.includeTime - ? ` (${Math.floor(e.time_listened / 60)} minutes)` - : ``} - -
- ))} -
-
-
-
- -
-
-

Top Album

-
-
-

{props.stats.top_albums[0].title}

- - {`${props.stats.top_albums[0].listen_count} plays`} - {props.includeTime - ? ` (${Math.floor( - props.stats.top_albums[0].time_listened / 60 - )} minutes)` - : ``} - -
-
- {props.stats.top_albums.slice(1).map((e, i) => ( -
- {e.title} - - {` - ${e.listen_count} plays`} - {props.includeTime - ? ` (${Math.floor(e.time_listened / 60)} minutes)` - : ``} - -
- ))} -
-
-
-
- -
-
-

Top Track

-
-
-

{props.stats.top_tracks[0].title}

- - {`${props.stats.top_tracks[0].listen_count} plays`} - {props.includeTime - ? ` (${Math.floor( - props.stats.top_tracks[0].time_listened / 60 - )} minutes)` - : ``} - -
-
- {props.stats.top_tracks.slice(1).map((e, i) => ( -
- {e.title} - - {` - ${e.listen_count} plays`} - {props.includeTime - ? ` (${Math.floor(e.time_listened / 60)} minutes)` - : ``} - -
- ))} -
+ a.name} + includeTime={props.includeTime} + /> + + a.title} + includeTime={props.includeTime} + /> + + t.title} + includeTime={props.includeTime} + /> + +
+ + + + + + + + +
); diff --git a/client/app/components/rewind/RewindStatText.tsx b/client/app/components/rewind/RewindStatText.tsx new file mode 100644 index 0000000..6a86a57 --- /dev/null +++ b/client/app/components/rewind/RewindStatText.tsx @@ -0,0 +1,32 @@ +interface Props { + figure: string; + text: string; +} + +export default function RewindStatText(props: Props) { + return ( +
+
+ + + {props.figure} + +
+ {props.text} +
+ ); +} diff --git a/client/app/components/rewind/RewindTopItem.tsx b/client/app/components/rewind/RewindTopItem.tsx index 187a1c3..d761b5a 100644 --- a/client/app/components/rewind/RewindTopItem.tsx +++ b/client/app/components/rewind/RewindTopItem.tsx @@ -1,30 +1,53 @@ -import { imageUrl, type Artist } from "api/api"; +type TopItemProps = { + title: string; + imageSrc: string; + items: T[]; + getLabel: (item: T) => string; + includeTime?: boolean; +}; -interface args { - title?: string; - name?: string; - image: string; - minutes_listened: number; - time_listened: number; - artists?: Artist; -} - -export default function RewindTopItem(args: args[]) { - console.log(args); - if (args === undefined || args.length < 1) { - return <>; +export function RewindTopItem< + T extends { + id: string | number; + listen_count: number; + time_listened: number; } - const img = imageUrl(args[0].image, "medium"); +>({ title, imageSrc, items, getLabel, includeTime }: TopItemProps) { + const [top, ...rest] = items; + + if (!top) return null; return ( -
+
- +
+
-

{args[0].title || args[0].name}

- {args.map((e) => ( -
{e.title || e.name}
+

{title}

+ +
+
+

{getLabel(top)}

+ + {`${top.listen_count} plays`} + {includeTime + ? ` (${Math.floor(top.time_listened / 60)} minutes)` + : ``} + +
+
+ + {rest.map((e) => ( +
+ {getLabel(e)} + + {` - ${e.listen_count} plays`} + {includeTime + ? ` (${Math.floor(e.time_listened / 60)} minutes)` + : ``} + +
))}
diff --git a/client/app/routes/RewindPage.tsx b/client/app/routes/RewindPage.tsx index db02cfb..b3ef0da 100644 --- a/client/app/routes/RewindPage.tsx +++ b/client/app/routes/RewindPage.tsx @@ -12,5 +12,5 @@ export default function RewindPage() { useEffect(() => { getRewindStats({ year: 2025 }).then((r) => setStats(r)); }, []); - return <>{stats !== undefined && }; + return <>{stats !== undefined && }; }