import { useState } from "react"; import { useLoaderData, type LoaderFunctionArgs } from "react-router"; import TopTracks from "~/components/TopTracks"; import { mergeArtists, type Artist } from "api/api"; import LastPlays from "~/components/LastPlays"; import PeriodSelector from "~/components/PeriodSelector"; import MediaLayout from "./MediaLayout"; import ArtistAlbums from "~/components/ArtistAlbums"; import ActivityGrid from "~/components/ActivityGrid"; import { timeListenedString } from "~/utils/utils"; export async function clientLoader({ params }: LoaderFunctionArgs) { const res = await fetch(`/apis/web/v1/artist?id=${params.id}`); if (!res.ok) { throw new Response("Failed to load artist", { status: 500 }); } const artist: Artist = await res.json(); return artist; } export default function Artist() { const artist = useLoaderData() as Artist; const [period, setPeriod] = useState('week') // remove canonical name from alias list console.log(artist.aliases) let index = artist.aliases.indexOf(artist.name); if (index !== -1) { artist.aliases.splice(index, 1); } return ( { r.albums = [] r.tracks = [] for (let i = 0; i < r.artists.length; i ++) { if (r.artists[i].id === id) { delete r.artists[i] } } return r }} subContent={
{artist.listen_count &&

{artist.listen_count} play{ artist.listen_count > 1 ? 's' : ''}

} {

{timeListenedString(artist.time_listened)}

}
} >
); }