2022-04-21 16:06:45 +00:00
|
|
|
import { reactive } from 'vue'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { http } from '@/services'
|
2024-06-02 17:15:31 +00:00
|
|
|
import { albumStore, artistStore, songStore } from '@/stores'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
interface ExcerptState {
|
2024-05-19 05:49:42 +00:00
|
|
|
playables: Playable[]
|
|
|
|
albums: Album[]
|
2022-07-23 11:07:14 +00:00
|
|
|
artists: Artist[]
|
2024-05-19 05:49:42 +00:00
|
|
|
podcasts: Podcast[]
|
2022-07-23 11:07:14 +00:00
|
|
|
}
|
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
export interface ExcerptSearchResult {
|
2024-05-19 05:49:42 +00:00
|
|
|
songs: Playable[] // backward compatibility
|
|
|
|
albums: Album[]
|
|
|
|
artists: Artist[]
|
|
|
|
podcasts: Podcast[]
|
|
|
|
}
|
2022-07-23 11:07:14 +00:00
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
export const searchStore = {
|
2022-04-21 16:06:45 +00:00
|
|
|
state: reactive({
|
2022-04-15 14:24:30 +00:00
|
|
|
excerpt: {
|
2024-05-19 05:49:42 +00:00
|
|
|
playables: [],
|
2022-07-23 11:07:14 +00:00
|
|
|
albums: [],
|
2024-05-19 05:49:42 +00:00
|
|
|
artists: [],
|
2024-10-13 17:37:01 +00:00
|
|
|
podcasts: [],
|
2022-07-23 11:07:14 +00:00
|
|
|
} as ExcerptState,
|
2024-10-13 17:37:01 +00:00
|
|
|
playables: [] as Playable[],
|
2022-04-21 16:06:45 +00:00
|
|
|
}),
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-21 16:06:45 +00:00
|
|
|
async excerptSearch (q: string) {
|
2022-09-15 09:07:25 +00:00
|
|
|
const result = await http.get<ExcerptSearchResult>(`search?q=${q}`)
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
this.state.excerpt.playables = songStore.syncWithVault(result.songs)
|
2022-06-10 10:47:46 +00:00
|
|
|
this.state.excerpt.albums = albumStore.syncWithVault(result.albums)
|
|
|
|
this.state.excerpt.artists = artistStore.syncWithVault(result.artists)
|
2024-05-19 05:49:42 +00:00
|
|
|
this.state.excerpt.podcasts = result.podcasts
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
async playableSearch (q: string) {
|
|
|
|
this.state.playables = songStore.syncWithVault(await http.get<Playable[]>(`search/songs?q=${q}`))
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
resetPlayableResultState () {
|
|
|
|
this.state.playables = []
|
2024-10-13 17:37:01 +00:00
|
|
|
},
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|