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({ return Response.json({
artist: track['artistName'], artist: track['artistName'],
title: track['name'], title: track['name'],
emoji: '🎧', text: `🎧 ${track['name']} by ${track['artistName']}`,
}) })
} }

View file

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

View file

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