remove old artistInfo

This commit is contained in:
austinried
2022-03-19 10:14:29 +09:00
parent 521b2abfcd
commit 7e33b0591e
3 changed files with 1 additions and 77 deletions

View File

@@ -6,13 +6,6 @@ export interface Artist {
coverArt?: string coverArt?: string
} }
export interface ArtistInfo extends Artist {
albums: Album[]
smallImageUrl?: string
largeImageUrl?: string
topSongs: Song[]
}
export interface AlbumListItem { export interface AlbumListItem {
itemType: 'album' itemType: 'album'
id: string id: string

View File

@@ -2,7 +2,6 @@ import {
AlbumListItem, AlbumListItem,
AlbumWithSongs, AlbumWithSongs,
Artist, Artist,
ArtistInfo,
HomeLists, HomeLists,
PlaylistListItem, PlaylistListItem,
PlaylistWithSongs, PlaylistWithSongs,
@@ -18,9 +17,6 @@ export type MusicSlice = {
// //
// family-style state // family-style state
// //
artistInfo: { [id: string]: ArtistInfo }
fetchArtistInfo: (id: string) => Promise<ArtistInfo | undefined>
albumsWithSongs: { [id: string]: AlbumWithSongs } albumsWithSongs: { [id: string]: AlbumWithSongs }
fetchAlbumWithSongs: (id: string) => Promise<AlbumWithSongs | undefined> fetchAlbumWithSongs: (id: string) => Promise<AlbumWithSongs | undefined>
@@ -60,7 +56,6 @@ export type MusicSlice = {
} }
export const selectMusic = { export const selectMusic = {
fetchArtistInfo: (state: Store) => state.fetchArtistInfo,
fetchAlbumWithSongs: (state: Store) => state.fetchAlbumWithSongs, fetchAlbumWithSongs: (state: Store) => state.fetchAlbumWithSongs,
fetchPlaylistWithSongs: (state: Store) => state.fetchPlaylistWithSongs, fetchPlaylistWithSongs: (state: Store) => state.fetchPlaylistWithSongs,
@@ -91,41 +86,6 @@ function reduceStarred(
} }
export const createMusicSlice = (set: SetState<Store>, get: GetState<Store>): MusicSlice => ({ export const createMusicSlice = (set: SetState<Store>, get: GetState<Store>): MusicSlice => ({
artistInfo: {},
fetchArtistInfo: async id => {
const client = get().client
if (!client) {
return undefined
}
try {
const [artistResponse, artistInfoResponse] = await Promise.all([
client.getArtist({ id }),
client.getArtistInfo2({ id }),
])
const topSongsResponse = await client.getTopSongs({ artist: artistResponse.data.artist.name, count: 50 })
const artistInfo = await get().mapArtistInfo(
artistResponse.data,
artistInfoResponse.data.artistInfo,
topSongsResponse.data.songs,
)
set(
produce<MusicSlice>(state => {
state.artistInfo[id] = artistInfo
state.starredSongs = reduceStarred(state.starredSongs, artistInfo.topSongs)
state.starredArtists = reduceStarred(state.starredArtists, [artistInfo])
state.starredAlbums = reduceStarred(state.starredAlbums, artistInfo.albums)
}),
)
return artistInfo
} catch {
return undefined
}
},
albumsWithSongs: {}, albumsWithSongs: {},
fetchAlbumWithSongs: async id => { fetchAlbumWithSongs: async id => {

View File

@@ -1,21 +1,11 @@
import { import { AlbumListItem, AlbumWithSongs, Artist, PlaylistListItem, PlaylistWithSongs, Song } from '@app/models/music'
AlbumListItem,
AlbumWithSongs,
Artist,
ArtistInfo,
PlaylistListItem,
PlaylistWithSongs,
Song,
} from '@app/models/music'
import { import {
AlbumID3Element, AlbumID3Element,
ArtistID3Element, ArtistID3Element,
ArtistInfo2Element,
ChildElement, ChildElement,
PlaylistElement, PlaylistElement,
PlaylistWithSongsElement, PlaylistWithSongsElement,
} from '@app/subsonic/elements' } from '@app/subsonic/elements'
import { GetArtistResponse } from '@app/subsonic/responses'
import { GetState, SetState } from 'zustand' import { GetState, SetState } from 'zustand'
import { Store } from './store' import { Store } from './store'
@@ -23,11 +13,6 @@ export type MusicMapSlice = {
mapChildToSong: (child: ChildElement, coverArt?: string) => Promise<Song> mapChildToSong: (child: ChildElement, coverArt?: string) => Promise<Song>
mapChildrenToSongs: (children: ChildElement[], coverArt?: string) => Promise<Song[]> mapChildrenToSongs: (children: ChildElement[], coverArt?: string) => Promise<Song[]>
mapArtistID3toArtist: (artist: ArtistID3Element) => Artist mapArtistID3toArtist: (artist: ArtistID3Element) => Artist
mapArtistInfo: (
artistResponse: GetArtistResponse,
info: ArtistInfo2Element,
topSongs: ChildElement[],
) => Promise<ArtistInfo>
mapAlbumID3toAlbumListItem: (album: AlbumID3Element) => AlbumListItem mapAlbumID3toAlbumListItem: (album: AlbumID3Element) => AlbumListItem
mapAlbumID3toAlbum: (album: AlbumID3Element) => AlbumListItem mapAlbumID3toAlbum: (album: AlbumID3Element) => AlbumListItem
mapAlbumID3WithSongstoAlbumWithSongs: (album: AlbumID3Element, songs: ChildElement[]) => Promise<AlbumWithSongs> mapAlbumID3WithSongstoAlbumWithSongs: (album: AlbumID3Element, songs: ChildElement[]) => Promise<AlbumWithSongs>
@@ -81,20 +66,6 @@ export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>):
} }
}, },
mapArtistInfo: async (artistResponse, info, topSongs) => {
const { artist, albums } = artistResponse
const mappedAlbums = albums.map(get().mapAlbumID3toAlbum)
return {
...get().mapArtistID3toArtist(artist),
albums: mappedAlbums,
smallImageUrl: info.smallImageUrl,
largeImageUrl: info.largeImageUrl,
topSongs: (await get().mapChildrenToSongs(topSongs)).slice(0, 5),
}
},
mapAlbumID3toAlbumListItem: album => { mapAlbumID3toAlbumListItem: album => {
return { return {
itemType: 'album', itemType: 'album',