33 class =" flex items-center justify-center"
44 overlay-transition =" vfm-fade"
55 content-transition =" vfm-fade"
6- content-class =" max-w-screen modal-box opacity-100" >
7- <div v-if =" currentResponse " class =" text-xl" >
8- {{ currentResponse .playlist?.title || currentResponse .system_playlist?.title }}
6+ content-class =" max-w-screen modal-box opacity-100 " >
7+ <div v-if =" currentResp " class =" text-xl" >
8+ {{ currentResp .playlist?.title || currentResp .system_playlist?.title }}
99 </div >
1010 <div >
11- <TrackList :tracks =" tracks" :playlist-response =" currentResponse" />
11+ <TrackList :tracks =" tracks" :playlist-response =" currentResp" >
12+ <template #bottom >
13+ <template v-if =" loading " >
14+ <div class =" loading loading-spinner loading-lg" ></div >
15+ <span class =" ml-2" >{{ $t("cloudie.common.loading") }}</span >
16+ </template >
17+
18+ <template v-else >
19+ <span class =" ml-2" >{{ $t("cloudie.common.noMore") }}</span >
20+ </template >
21+ </template >
22+ </TrackList >
1223 </div >
1324 <div class =" modal-action" >
1425 <button class =" btn" @click =" emit('close')" >{{ $t("cloudie.toasts.close") }}</button >
@@ -22,30 +33,55 @@ import TrackList from "../TrackList.vue"
2233import { Playlist , PlaylistLike , SystemPlaylist , Track } from " @/utils/types"
2334import { onMounted , ref } from " vue"
2435import { fetchPlaylistUpdates } from " @/systems/cache"
36+ import { getPlaylist } from " @/systems/cache"
37+ import { toast } from " vue-sonner"
38+ import { i18n } from " @/systems/i18n"
39+ import { savePlaylist } from " @/systems/cache"
2540
2641const props = defineProps <{
27- tracks: Track []
28- currentResponse: PlaylistLike
29- shouldAutoUpdate: boolean
42+ currentResp: PlaylistLike
3043}>()
3144
32- const playlistRef = ref (props .currentResponse )
33-
34- onMounted (() => {
35- if (props .shouldAutoUpdate ) {
36- // Reactively update playtlist meta
37- fetchPlaylistUpdates (
38- props .currentResponse ,
39- (props .currentResponse .playlist ?? props .currentResponse .system_playlist ).tracks ! .map (
40- (t ) => t .id ,
41- ),
42- ).then ((playlist ) => {
43- if (playlistRef .value .system_playlist ) {
44- playlistRef .value .system_playlist = playlist as SystemPlaylist
45- } else {
46- playlistRef .value .playlist = playlist as Playlist
47- }
45+ const playlistRef = ref (props .currentResp )
46+ const loading = ref (true )
47+ const tracks = ref <Track []>([])
48+
49+ onMounted (async () => {
50+ let playlistId = props .currentResp .playlist
51+ ? props .currentResp .playlist .id
52+ : props .currentResp .system_playlist .id
53+
54+ try {
55+ let currentPlaylist = await getPlaylist (playlistId )
56+ const newCreatedPlaylist = ! currentPlaylist
57+ if (newCreatedPlaylist ) {
58+ currentPlaylist = await fetchPlaylistUpdates (props .currentResp )
59+ }
60+
61+ tracks .value = currentPlaylist ! .tracks as Track []
62+ loading .value = false
63+
64+ await savePlaylist (currentPlaylist )
65+
66+ if (! newCreatedPlaylist ) {
67+ // Reactively update playtlist meta
68+ fetchPlaylistUpdates (
69+ props .currentResp ,
70+ (props .currentResp .playlist ?? props .currentResp .system_playlist ).tracks ! .map ((t ) => t .id ), // FIXME: Undefinded???
71+ ).then ((playlist ) => {
72+ if (playlistRef .value .system_playlist ) {
73+ playlistRef .value .system_playlist = playlist as SystemPlaylist
74+ } else {
75+ playlistRef .value .playlist = playlist as Playlist
76+ }
77+ })
78+ }
79+ } catch (err : any ) {
80+ console .error (" PlaylistList open error:" , err )
81+ toast .error (i18n .global .t (" cloudie.toasts.playlistOpenFailed" ), {
82+ description: err .message ,
4883 })
84+ return
4985 }
5086})
5187
0 commit comments