From af01392f202a699ddc25a11230499f99d34cff19 Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sun, 27 Apr 2025 23:02:01 -0400 Subject: [PATCH] truncate music name if too long --- src/App.tsx | 4 +- src/components/MusicComponent.tsx | 112 +++++++++++++++--------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9e30e9a..c174442 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -142,8 +142,8 @@ export default function MouseFlashlight() { -
-
+
+

diff --git a/src/components/MusicComponent.tsx b/src/components/MusicComponent.tsx index d391603..6a6c584 100644 --- a/src/components/MusicComponent.tsx +++ b/src/components/MusicComponent.tsx @@ -1,63 +1,63 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect } from "react"; type MusicObject = { - artist: { - mbid: string, - "#text": string - }, - name: string, - image: ImageObject[], - url: string -} + artist: { + mbid: string; + "#text": string; + }; + name: string; + image: ImageObject[]; + url: string; +}; type ImageObject = { - size: "small" | "medium" | "large" | "extralarge", - "#text": string -} + size: "small" | "medium" | "large" | "extralarge"; + "#text": string; +}; export default function MusicComponent() { - const [ music, setMusic ] = useState(null); - const [ failedFetch, setFailedFetch ] = useState(false); + const [music, setMusic] = useState(null); + const [failedFetch, setFailedFetch] = useState(false); - 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 MusicObject) - } else setFailedFetch(true) - } - - setTimeout(() => { - fetchMusic() - }, 60000) - fetchMusic() - }, []) - - if (music) { - return ( -
- -
-

{music.name}

-

{music.artist['#text']}

-
-
- ) - } else { - if (failedFetch) { - return ( -
-

uh oh!

-

failed to get music :(

-
- ) - } else { - return ( -
-

loading music..

-

loading artist..

-
- ) - } + 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 MusicObject); + } else setFailedFetch(true); } -} \ No newline at end of file + + setTimeout(() => { + fetchMusic(); + }, 60000); + fetchMusic(); + }, []); + + if (music) { + return ( +
+ +
+

{music.name}

+

{music.artist["#text"]}

+
+
+ ); + } else { + if (failedFetch) { + return ( +
+

uh oh!

+

failed to get music :(

+
+ ); + } else { + return ( +
+

loading music..

+

loading artist..

+
+ ); + } + } +}