spotifyplaylistarchive.com/pages/playlists/[playlistId].vue

79 lines
2.0 KiB
Vue
Raw Normal View History

2022-07-02 15:21:04 +02:00
<script setup lang="ts">
import TabMenu from 'primevue/tabmenu';
2022-07-13 19:53:05 +02:00
import { Snapshot } from '~~/models/snapshot';
2022-07-02 15:21:04 +02:00
const route = useRoute();
const playlistId = route.params.playlistId;
const tabItems = [
{
label: 'Browse snapshots',
icon: 'pi pi-calendar',
to: `/playlists/${playlistId}/snapshots`
2022-07-02 15:21:04 +02:00
},
{
label: 'Show statistics',
icon: 'pi pi-chart-bar',
to: `/playlists/${playlistId}/stats`
2022-07-02 15:21:04 +02:00
}
2022-07-21 11:13:23 +02:00
// {
// label: 'Compare snapshots (SOON)',
// icon: 'pi pi-sort-alt',
// to: `/playlists/${playlistId}/snapshots/compare`,
// disabled: true
// }
2022-07-02 15:21:04 +02:00
];
2022-07-13 19:53:05 +02:00
const { error, data: playlist } = await useFetch<Snapshot>(
2022-07-02 15:21:04 +02:00
() =>
2022-07-06 14:02:10 +02:00
`https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/main/playlists/pretty/${playlistId}.json`,
2022-07-02 15:21:04 +02:00
{
parseResponse: (body) =>
2022-07-13 19:53:05 +02:00
body === '404: Not Found' ? null : JSON.parse(body),
2022-07-02 15:21:04 +02:00
key: `playlist-${playlistId}`
}
);
const isNotFoundError = computed(
() => typeof error.value !== 'boolean' && error.value.message.includes('404')
);
</script>
<template>
<div class="flex flex-column align-items-center mt-7">
<p v-if="error" class="text-xl">
<span v-if="isNotFoundError">
This playlist was not found in the registry
</span>
<span v-else>Something went wrong while fetching playlist's data</span>
</p>
2022-07-06 14:02:10 +02:00
<template v-else-if="playlist">
2022-07-02 15:21:04 +02:00
<h1 class="text-3xl mb-3">
2022-07-06 14:02:10 +02:00
<NuxtLink :to="playlist.url" target="_blank">
{{ playlist.unique_name }}
<span v-if="playlist.unique_name !== playlist.original_name">
({{ playlist.original_name }})
2022-07-02 15:21:04 +02:00
</span>
</NuxtLink>
by
2022-07-06 14:02:10 +02:00
<NuxtLink :to="playlist.owner?.url" target="_blank">
{{ playlist.owner?.name }}
2022-07-02 15:21:04 +02:00
</NuxtLink>
</h1>
2022-07-21 11:13:23 +02:00
<TabMenu class="md:w-10 w-full mb-4" :model="tabItems" />
2022-07-02 15:21:04 +02:00
<NuxtPage />
</template>
</div>
</template>
<style scoped>
:deep(ul.p-tabmenu-nav) {
justify-content: center;
}
:deep(.p-tabmenu .p-tabmenu-nav .p-tabmenuitem a.p-menuitem-link) {
background-color: transparent;
}
</style>