adding recently played and restructured spotify components
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<nav class="no-print flex-row">
|
<nav class="no-print flex-row">
|
||||||
<RouterLink to="/">Home</RouterLink>
|
<RouterLink to="/"><h1>HOME</h1></RouterLink>
|
||||||
<RouterLink to="/cv">CV</RouterLink>
|
<RouterLink to="/cv"><h1>CV</h1></RouterLink>
|
||||||
</nav>
|
</nav>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style scoped>
|
||||||
nav {
|
nav {
|
||||||
height: 10vh;
|
height: 10vh;
|
||||||
}
|
}
|
||||||
|
a {
|
||||||
|
rotate: -50deg;
|
||||||
|
height: 100%;
|
||||||
|
background: white;
|
||||||
|
padding: 4px;
|
||||||
|
border: 2px solid black;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="playing" class="spotify-now-playing">
|
<div v-if="song.is_playing" class="spotify-now-playing">
|
||||||
<img :src="albumImage" />
|
<img :src="song.item.album.images[0].url" />
|
||||||
<p><strong>Song:</strong> {{ songName }}</p>
|
<p><strong>Song:</strong> {{ song.item.name }}</p>
|
||||||
<p><strong>Artist:</strong> {{ artistName }}</p>
|
<p><strong>Artist:</strong> {{ song.item.artists[0].name }}</p>
|
||||||
<p>Is what im currently listening to rnrnrn ^_^</p>
|
<p>Is what im currently listening to rnrnrn ^_^</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="spotify-not-playing">
|
<div v-else class="spotify-not-playing">
|
||||||
@@ -15,29 +15,16 @@
|
|||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "SpotifyNowPlaying",
|
name: "spotify-listening",
|
||||||
setup() {
|
setup() {
|
||||||
const albumImage = ref("");
|
const song = ref({});
|
||||||
const artistName = ref("");
|
|
||||||
const songName = ref("");
|
|
||||||
const songUrl = ref("");
|
|
||||||
const playing = ref(false);
|
|
||||||
|
|
||||||
async function fetchSpotify() {
|
async function fetchSpotify() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/spotify");
|
const res = await fetch("/api/spotify/listening");
|
||||||
if (!res.ok) throw new Error("Failed to fetch Spotify data");
|
if (!res.ok) throw new Error("Failed to fetch Spotify data");
|
||||||
const data = await res.json();
|
song.value = await res.json();
|
||||||
if (playing.value == false) {
|
console.log(data);
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
albumImage.value = data.album_image;
|
|
||||||
artistName.value = data.artist_name;
|
|
||||||
songUrl.value = data.song_url;
|
|
||||||
songName.value = data.song_name;
|
|
||||||
playing.value = data.playing;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
63
nginx/vue/src/components/spotify/Recent.vue
Normal file
63
nginx/vue/src/components/spotify/Recent.vue
Normal file
@@ -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>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Spotify from "@/components/Spotify.vue";
|
import SpotifyListening from "@/components/spotify/Listening.vue";
|
||||||
|
import SpotifyRecent from "@/components/spotify/Recent.vue";
|
||||||
import Radio from "@/components/Radio.vue";
|
import Radio from "@/components/Radio.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -49,8 +50,13 @@ import Radio from "@/components/Radio.vue";
|
|||||||
</div> -->
|
</div> -->
|
||||||
|
|
||||||
<div class="bordered-1">
|
<div class="bordered-1">
|
||||||
<Spotify class="border" />
|
<SpotifyListening class="border" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="bordered-1">
|
||||||
|
<SpotifyRecent class="border" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="bordered-1">
|
<div class="bordered-1">
|
||||||
<Radio />
|
<Radio />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user