truncate music name if too long
This commit is contained in:
+2
-2
@@ -142,8 +142,8 @@ export default function MouseFlashlight() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="border border-white border-solid rounded-lg w-full sm:w-[500px]">
|
<div className="border border-white border-solid rounded-lg w-full sm:w-[500px] p-2">
|
||||||
<div className="grid grid-cols-1 xs:grid-cols-2 p-2">
|
<div className="grid grid-cols-1 xs:grid-cols-2">
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold italic opacity-95 inline">
|
<h1 className="text-2xl font-bold italic opacity-95 inline">
|
||||||
|
|||||||
@@ -1,63 +1,63 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
type MusicObject = {
|
type MusicObject = {
|
||||||
artist: {
|
artist: {
|
||||||
mbid: string,
|
mbid: string;
|
||||||
"#text": string
|
"#text": string;
|
||||||
},
|
};
|
||||||
name: string,
|
name: string;
|
||||||
image: ImageObject[],
|
image: ImageObject[];
|
||||||
url: string
|
url: string;
|
||||||
}
|
};
|
||||||
type ImageObject = {
|
type ImageObject = {
|
||||||
size: "small" | "medium" | "large" | "extralarge",
|
size: "small" | "medium" | "large" | "extralarge";
|
||||||
"#text": string
|
"#text": string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function MusicComponent() {
|
export default function MusicComponent() {
|
||||||
const [ music, setMusic ] = useState<MusicObject | null>(null);
|
const [music, setMusic] = useState<MusicObject | null>(null);
|
||||||
const [ failedFetch, setFailedFetch ] = useState(false);
|
const [failedFetch, setFailedFetch] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchMusic() {
|
async function fetchMusic() {
|
||||||
const response = await fetch("https://api.alexav.gg/v4/social/music")
|
const response = await fetch("https://api.alexav.gg/v4/social/music");
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json()
|
const data = await response.json();
|
||||||
setMusic(data.data.tracks[0] as MusicObject)
|
setMusic(data.data.tracks[0] as MusicObject);
|
||||||
} else setFailedFetch(true)
|
} else setFailedFetch(true);
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
fetchMusic()
|
|
||||||
}, 60000)
|
|
||||||
fetchMusic()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (music) {
|
|
||||||
return (
|
|
||||||
<div className="flex align-middle">
|
|
||||||
<img width="50" src={music.image[1]['#text']} />
|
|
||||||
<div className="pl-2">
|
|
||||||
<h1>{music.name}</h1>
|
|
||||||
<p>{music.artist['#text']}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
if (failedFetch) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>uh oh!</h1>
|
|
||||||
<p>failed to get music :(</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>loading music..</h1>
|
|
||||||
<p>loading artist..</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
setTimeout(() => {
|
||||||
|
fetchMusic();
|
||||||
|
}, 60000);
|
||||||
|
fetchMusic();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (music) {
|
||||||
|
return (
|
||||||
|
<div className="flex align-middle">
|
||||||
|
<img width="50" src={music.image[1]["#text"]} />
|
||||||
|
<div className="pl-2 max-w-25">
|
||||||
|
<h1 className="truncate">{music.name}</h1>
|
||||||
|
<p className="truncate">{music.artist["#text"]}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (failedFetch) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>uh oh!</h1>
|
||||||
|
<p>failed to get music :(</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>loading music..</h1>
|
||||||
|
<p>loading artist..</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user