2024-04-29 19:31:54 +00:00
|
|
|
import { reactive, watch } from 'vue'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { http } from '@/services'
|
2022-06-10 10:47:46 +00:00
|
|
|
import { songStore } from '@/stores/songStore'
|
|
|
|
import { albumStore } from '@/stores/albumStore'
|
|
|
|
import { artistStore } from '@/stores/artistStore'
|
|
|
|
import { recentlyPlayedStore } from '@/stores'
|
2024-06-02 17:15:31 +00:00
|
|
|
import { isEpisode, isSong } from '@/utils'
|
2022-06-10 10:47:46 +00:00
|
|
|
|
|
|
|
export const overviewStore = {
|
|
|
|
state: reactive({
|
2024-06-02 17:15:31 +00:00
|
|
|
recentlyPlayed: [] as Playable[],
|
2022-09-12 15:33:41 +00:00
|
|
|
recentlyAddedSongs: [] as Song[],
|
|
|
|
recentlyAddedAlbums: [] as Album[],
|
2024-06-02 17:15:31 +00:00
|
|
|
mostPlayedSongs: [] as Playable[],
|
2022-09-12 15:33:41 +00:00
|
|
|
mostPlayedAlbums: [] as Album[],
|
|
|
|
mostPlayedArtists: [] as Artist[]
|
2022-06-10 10:47:46 +00:00
|
|
|
}),
|
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
async fetch () {
|
2022-09-15 09:07:25 +00:00
|
|
|
const resource = await http.get<{
|
2024-06-02 17:15:31 +00:00
|
|
|
most_played_songs: Playable[],
|
2022-06-10 10:47:46 +00:00
|
|
|
most_played_albums: Album[],
|
|
|
|
most_played_artists: Artist[],
|
|
|
|
recently_added_songs: Song[],
|
|
|
|
recently_added_albums: Album[],
|
2024-06-02 17:15:31 +00:00
|
|
|
recently_played_songs: Playable[],
|
2022-06-10 10:47:46 +00:00
|
|
|
}>('overview')
|
|
|
|
|
2022-10-11 15:28:43 +00:00
|
|
|
songStore.syncWithVault(resource.most_played_songs)
|
|
|
|
albumStore.syncWithVault(resource.recently_added_albums)
|
2022-06-10 10:47:46 +00:00
|
|
|
artistStore.syncWithVault(resource.most_played_artists)
|
|
|
|
|
2022-10-11 15:28:43 +00:00
|
|
|
this.state.mostPlayedAlbums = albumStore.syncWithVault(resource.most_played_albums)
|
|
|
|
this.state.mostPlayedArtists = artistStore.syncWithVault(resource.most_played_artists)
|
2024-06-02 17:15:31 +00:00
|
|
|
this.state.recentlyAddedSongs = songStore.syncWithVault(resource.recently_added_songs) as Song[]
|
2022-10-11 15:28:43 +00:00
|
|
|
this.state.recentlyAddedAlbums = albumStore.syncWithVault(resource.recently_added_albums)
|
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
recentlyPlayedStore.excerptState.playables = songStore.syncWithVault(resource.recently_played_songs)
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
this.refreshPlayStats()
|
2022-06-10 10:47:46 +00:00
|
|
|
},
|
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
refreshPlayStats () {
|
2022-06-10 10:47:46 +00:00
|
|
|
this.state.mostPlayedSongs = songStore.getMostPlayed(7)
|
2024-06-02 17:15:31 +00:00
|
|
|
this.state.recentlyPlayed = recentlyPlayedStore.excerptState.playables.filter(playable => {
|
|
|
|
if (isSong(playable) && playable.deleted) return false
|
|
|
|
return playable.play_count > 0
|
|
|
|
})
|
2022-06-10 10:47:46 +00:00
|
|
|
}
|
|
|
|
}
|