refactor star

This commit is contained in:
austinried
2022-03-20 09:33:15 +09:00
parent 1803e9dc7c
commit a15159014c
10 changed files with 122 additions and 146 deletions

View File

@@ -15,6 +15,7 @@ import {
GetArtistsResponse,
GetPlaylistResponse,
GetPlaylistsResponse,
GetSongResponse,
GetTopSongsResponse,
Search3Response,
SubsonicResponse,
@@ -184,6 +185,8 @@ export type LibrarySlice = {
fetchLibraryPlaylists: () => Promise<void>
fetchLibraryPlaylist: (id: string) => Promise<void>
fetchLibrarySong: (id: string) => Promise<void>
fetchLibraryAlbumList: (params: GetAlbumList2Params) => Promise<string[]>
fetchLibrarySearchResults: (params: Search3Params) => Promise<SearchResults>
star: (params: StarParams) => Promise<void>
@@ -405,6 +408,28 @@ export const createLibrarySlice = (set: SetState<Store>, get: GetState<Store>):
)
},
fetchLibrarySong: async id => {
const client = get().client
if (!client) {
return
}
let response: SubsonicResponse<GetSongResponse>
try {
response = await client.getSong({ id })
} catch {
return
}
const song = mapSong(response.data.song)
set(
produce<LibrarySlice>(state => {
state.entities.songs[id] = song
}),
)
},
fetchLibraryAlbumList: async params => {
const client = get().client
if (!client) {