2022-04-21 16:06:45 +00:00
|
|
|
import { reactive } from 'vue'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { httpService } from '@/services'
|
|
|
|
import { albumStore, artistStore, songStore } from '@/stores'
|
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: {
|
|
|
|
songs: [] as Song[],
|
|
|
|
albums: [] as Album[],
|
|
|
|
artists: [] as Artist[]
|
|
|
|
},
|
2022-04-21 16:06:45 +00:00
|
|
|
songs: [] as Song[]
|
|
|
|
}),
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-21 16:06:45 +00:00
|
|
|
async excerptSearch (q: string) {
|
2022-06-10 10:47:46 +00:00
|
|
|
const result = await httpService.get<{
|
|
|
|
songs: Song[]
|
|
|
|
albums: Album[]
|
|
|
|
artists: Artist[]
|
|
|
|
}>(`search?q=${q}`)
|
|
|
|
|
|
|
|
this.state.excerpt.songs = songStore.syncWithVault(result.songs)
|
|
|
|
this.state.excerpt.albums = albumStore.syncWithVault(result.albums)
|
|
|
|
this.state.excerpt.artists = artistStore.syncWithVault(result.artists)
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
2022-04-21 16:06:45 +00:00
|
|
|
async songSearch (q: string) {
|
2022-06-10 10:47:46 +00:00
|
|
|
this.state.songs = songStore.syncWithVault(await httpService.get<Song[]>(`search/songs?q=${q}`))
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resetSongResultState () {
|
|
|
|
this.state.songs = []
|
|
|
|
}
|
|
|
|
}
|