diff --git a/components/TrackEntriesTable.vue b/components/snapshot/TrackEntries.vue similarity index 78% rename from components/TrackEntriesTable.vue rename to components/snapshot/TrackEntries.vue index 3f1fe3b..9511a96 100644 --- a/components/TrackEntriesTable.vue +++ b/components/snapshot/TrackEntries.vue @@ -25,17 +25,17 @@ const dateFormatter = new Intl.DateTimeFormat('en-US', { const formatDate = (date: string | null) => date ? dateFormatter.format(new Date(date)) : 'N/A'; -const displayRetentionText = (retention: number) => { +const formatRetentionText = (retention: number) => { const durationObject = intervalToDateFnsDuration({ start: 0, end: retention }); - const displayText = dateFnsFormatDuration(durationObject, { + const formattedText = dateFnsFormatDuration(durationObject, { format: ['years', 'months', 'days'], delimiter: ', ' }); - return displayText; + return formattedText; }; @@ -60,16 +60,14 @@ const displayRetentionText = (retention: number) => { @@ -94,23 +92,17 @@ const displayRetentionText = (retention: number) => { diff --git a/components/stats/TrackRetention.vue b/components/stats/TrackRetention.vue index e79818e..b23a71f 100644 --- a/components/stats/TrackRetention.vue +++ b/components/stats/TrackRetention.vue @@ -2,6 +2,7 @@ import { $fetch } from 'ohmyfetch'; import { Cumulative } from '~~/models/cumulative'; +import { Track } from '~~/models/track'; const route = useRoute(); const playlistId = route.params.playlistId as string; @@ -17,17 +18,19 @@ const { `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/main/playlists/cumulative/${playlistId}.json`, { parseResponse: JSON.parse } ); - const now = new Date().toISOString(); + const now = Date.now(); return tracks .map((track) => { track.retention = - Date.parse(track.date_removed || now) - Date.parse(track.date_added); + (Date.parse(track.date_removed) || now) - + Date.parse(track.date_added); return track; }) .sort((a, b) => b.retention - a.retention); - } + }, + { default: () => [] as Track[] } ); @@ -37,13 +40,13 @@ const {

Something went wrong while fetching the longest standing tracks

- + diff --git a/pages/playlists/[playlistId]/snapshots/show/[commitSha].vue b/pages/playlists/[playlistId]/snapshots/show/[commitSha].vue index 52d03c4..086232e 100644 --- a/pages/playlists/[playlistId]/snapshots/show/[commitSha].vue +++ b/pages/playlists/[playlistId]/snapshots/show/[commitSha].vue @@ -15,7 +15,10 @@ const { } = useFetch( () => `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/${commitSha}/playlists/pretty/${playlistId}.json`, - { key: `snapshot-${commitSha}`, parseResponse: JSON.parse } + { + key: `snapshot-${commitSha}`, + parseResponse: JSON.parse + } ); const totalTrackDuration = computed(() => @@ -53,7 +56,7 @@ const humanizeNumber = (num: number) => numberFormatter.format(num); -