chore: simplify now playing

This commit is contained in:
Cory Dransfeldt 2023-10-07 11:57:00 -07:00
parent 06ca81b903
commit 282bc3a84d
3 changed files with 10 additions and 10 deletions

View file

@ -17,7 +17,7 @@ export default async () => {
return Response.json({
artist: track['artistName'],
title: track['name'],
emoji: '🎧',
text: `🎧 ${track['name']} by ${track['artistName']}`,
})
}

View file

@ -3,6 +3,6 @@
{% tablericon 'loader-2' 'Loading...' %}
</span>
<span id="now-playing-display">
<span id="now-playing-emoji"></span> <span id="now-playing-content"></span>
<span id="now-playing-content"></span>
</span>
</p>

View file

@ -1,14 +1,13 @@
;(async function () {
const nowPlaying = document.getElementById('now-playing')
if (nowPlaying) {
const emoji = document.getElementById('now-playing-emoji')
const content = document.getElementById('now-playing-content')
const loading = document.getElementById('now-playing-loading')
const populateNowPlaying = (data) => {
loading.style.display = 'none'
emoji.innerText = data.emoji
content.innerText = `${data.title} by ${data.artist}`
emoji.classList.remove('hidden')
content.innerText = data.text
content.classList.remove('hidden')
}
@ -19,12 +18,13 @@
/* quiet catch */
}
const res = await fetch('/api/now-playing', {
const data = await fetch('/api/now-playing', {
type: 'json',
}).catch(() => {
})
.then((data) => data.json())
.catch(() => {
loading.style.display = 'none'
})
const data = await res.json()
try {
localStorage.setItem('now-playing', JSON.stringify(data))