mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
set starred/unstar assuming it works
and correct state on error
This commit is contained in:
@@ -496,23 +496,41 @@ export const createLibrarySlice = (set: SetState<Store>, get: GetState<Store>):
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
let id = '-1'
|
||||||
await client.star(params)
|
let entity: 'songs' | 'artists' | 'albums' = 'songs'
|
||||||
} catch {
|
if (params.id) {
|
||||||
|
id = params.id
|
||||||
|
entity = 'songs'
|
||||||
|
} else if (params.albumId) {
|
||||||
|
id = params.albumId
|
||||||
|
entity = 'albums'
|
||||||
|
} else if (params.artistId) {
|
||||||
|
id = params.artistId
|
||||||
|
entity = 'artists'
|
||||||
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const item = get().entities[entity][id]
|
||||||
|
const originalValue = item ? item.starred : null
|
||||||
|
|
||||||
set(
|
set(
|
||||||
produce<LibrarySlice>(state => {
|
produce<LibrarySlice>(state => {
|
||||||
if (params.id) {
|
state.entities[entity][id].starred = new Date()
|
||||||
state.entities.songs[params.id].starred = new Date()
|
|
||||||
} else if (params.albumId) {
|
|
||||||
state.entities.albums[params.albumId].starred = new Date()
|
|
||||||
} else if (params.artistId) {
|
|
||||||
state.entities.artists[params.artistId].starred = new Date()
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.star(params)
|
||||||
|
} catch {
|
||||||
|
set(
|
||||||
|
produce<LibrarySlice>(state => {
|
||||||
|
if (originalValue !== null) {
|
||||||
|
state.entities[entity][id].starred = originalValue
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
unstar: async params => {
|
unstar: async params => {
|
||||||
@@ -521,22 +539,40 @@ export const createLibrarySlice = (set: SetState<Store>, get: GetState<Store>):
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
let id = '-1'
|
||||||
await client.unstar(params)
|
let entity: 'songs' | 'artists' | 'albums' = 'songs'
|
||||||
} catch {
|
if (params.id) {
|
||||||
|
id = params.id
|
||||||
|
entity = 'songs'
|
||||||
|
} else if (params.albumId) {
|
||||||
|
id = params.albumId
|
||||||
|
entity = 'albums'
|
||||||
|
} else if (params.artistId) {
|
||||||
|
id = params.artistId
|
||||||
|
entity = 'artists'
|
||||||
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const item = get().entities[entity][id]
|
||||||
|
const originalValue = item ? item.starred : null
|
||||||
|
|
||||||
set(
|
set(
|
||||||
produce<LibrarySlice>(state => {
|
produce<LibrarySlice>(state => {
|
||||||
if (params.id) {
|
state.entities[entity][id].starred = undefined
|
||||||
state.entities.songs[params.id].starred = undefined
|
|
||||||
} else if (params.albumId) {
|
|
||||||
state.entities.albums[params.albumId].starred = undefined
|
|
||||||
} else if (params.artistId) {
|
|
||||||
state.entities.artists[params.artistId].starred = undefined
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.unstar(params)
|
||||||
|
} catch {
|
||||||
|
set(
|
||||||
|
produce<LibrarySlice>(state => {
|
||||||
|
if (originalValue !== null) {
|
||||||
|
state.entities[entity][id].starred = originalValue
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user