diff --git a/src/components/MusicComponent.tsx b/src/components/MusicComponent.tsx index 0f5f397..9b88b30 100644 --- a/src/components/MusicComponent.tsx +++ b/src/components/MusicComponent.tsx @@ -7,11 +7,16 @@ export default function MusicComponent() { useEffect(() => { async function fetchMusic() { - const response = await fetch("https://api.alexav.gg/v4/social/music"); - if (response.ok) { - const data = await response.json(); - setMusic(data.data.tracks[0] as LastFMMusicObject); - } else setFailedFetch(true); + try { + const response = await fetch("https://api.alexav.gg/v4/social/music"); + if (response.ok) { + const data = await response.json(); + setMusic(data.data as LastFMMusicObject); + } else setFailedFetch(true); + } catch (e) { + console.error("Failed to fetch music!", e); + setFailedFetch(true); + } } setTimeout(() => { @@ -23,10 +28,10 @@ export default function MusicComponent() { if (music) { return (
- +
-

{music.name}

-

{music.artist["#text"]}

+

{music.title}

+

{music.artist}

); diff --git a/src/utils/types.ts b/src/utils/types.ts index fbdb4cc..a031fae 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,15 +1,12 @@ type LastFMMusicObject = { - artist: { - mbid: string; - "#text": string; - }; - name: string; - image: LastFMImageObject[]; + artist: string; + title: string; + images: LastFMImageObject[]; url: string; }; type LastFMImageObject = { size: "small" | "medium" | "large" | "extralarge"; - "#text": string; + url: string; }; // nfl stuff