adding recently played and restructured spotify components

This commit is contained in:
2025-11-29 00:53:37 +00:00
parent 160dd24bf2
commit e986044159
4 changed files with 90 additions and 27 deletions
@@ -0,0 +1,64 @@
<template>
<div v-if="song.is_playing" class="spotify-now-playing">
<img :src="song.item.album.images[0].url" />
<p><strong>Song:</strong> {{ song.item.name }}</p>
<p><strong>Artist:</strong> {{ song.item.artists[0].name }}</p>
<p>Is what im currently listening to rnrnrn ^_^</p>
</div>
<div v-else class="spotify-not-playing">
<img src="/img/Untitled.png" />
<p>I ain't listenin to nofin</p>
</div>
</template>
<script>
import { ref, onMounted } from "vue";
export default {
name: "spotify-listening",
setup() {
const song = ref({});
async function fetchSpotify() {
try {
const res = await fetch("/api/spotify/listening");
if (!res.ok) throw new Error("Failed to fetch Spotify data");
song.value = await res.json();
console.log(data);
} catch (err) {
console.error(err);
}
}
onMounted(() => {
fetchSpotify();
setInterval(fetchSpotify, 120000);
});
return {
albumImage,
artistName,
songName,
playing,
};
},
};
</script>
<style scoped>
.spotify-now-playing {
width: fit-content;
height: fit-content;
flex-direction: column;
align-items: center;
text-align: center;
box-shadow: 3px;
}
.spotify-not-playing {
border: 2px solid black;
align-items: center;
text-align: center;
background: white;
}
</style>
@@ -0,0 +1,63 @@
<template>
<div
v-for="(song, idx) in played"
:key="song.item.id || idx"
class="spotify-now-playing"
>
<img :src="song.item.album.images[0].url" />
<p><strong>Song:</strong> {{ song.item.name }}</p>
<p><strong>Artist:</strong> {{ song.item.artists[0].name }}</p>
<p>Is what im currently listening to rnrnrn ^_^</p>
</div>
</template>
<script>
import { ref, onMounted } from "vue";
export default {
name: "spotify-recent",
setup() {
const played = ref([]);
async function fetchRecent() {
try {
const res = await fetch("/api/spotify/recent");
if (!res.ok) throw new Error("Failed to fetch Spotify data");
played.value = await res.json();
} catch (err) {
console.error(err);
}
}
onMounted(() => {
fetchRecent();
setInterval(fetchRecent, 120000);
});
return {
albumImage,
artistName,
songName,
playing,
};
},
};
</script>
<style scoped>
.spotify-now-playing {
width: fit-content;
height: fit-content;
flex-direction: column;
align-items: center;
text-align: center;
box-shadow: 3px;
}
.spotify-not-playing {
border: 2px solid black;
align-items: center;
text-align: center;
background: white;
}
</style>