mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
add optimistic update for favorite/rating in song list queries
This commit is contained in:
@@ -520,6 +520,28 @@ export const applyFavoriteOptimisticUpdates = (
|
||||
}
|
||||
});
|
||||
|
||||
const songListQueryKey = queryKeys.songs.list(variables.apiClientProps.serverId);
|
||||
const songListQueries = queryClient.getQueriesData({
|
||||
exact: false,
|
||||
queryKey: songListQueryKey,
|
||||
});
|
||||
|
||||
songListQueries.forEach(([queryKey, data]) => {
|
||||
if (data) {
|
||||
pendingUpdates.push({
|
||||
previousData: data,
|
||||
queryKey,
|
||||
updater: (prev: { items: Song[] } | undefined) => {
|
||||
if (!prev) return prev;
|
||||
const updatedItems = updateItemInArray(prev.items, itemIdSet, (item) =>
|
||||
createFavoriteUpdater<Song>(item),
|
||||
);
|
||||
return updatedItems ? { ...prev, items: updatedItems } : prev;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const topSongsQueryKey = queryKeys.albumArtists.topSongs(
|
||||
variables.apiClientProps.serverId,
|
||||
);
|
||||
@@ -679,6 +701,10 @@ export const applyFavoriteOptimisticUpdatesDeferred = (
|
||||
queryKeys.playlists.songList(variables.apiClientProps.serverId),
|
||||
'playlist-song-list',
|
||||
);
|
||||
collectQueries(
|
||||
queryKeys.songs.list(variables.apiClientProps.serverId),
|
||||
'song-list',
|
||||
);
|
||||
collectQueries(
|
||||
queryKeys.albumArtists.topSongs(variables.apiClientProps.serverId),
|
||||
'top-songs',
|
||||
@@ -742,6 +768,7 @@ export const applyFavoriteOptimisticUpdatesDeferred = (
|
||||
case 'album-list':
|
||||
case 'artist-list':
|
||||
case 'playlist-song-list':
|
||||
case 'song-list':
|
||||
case 'top-songs': {
|
||||
const updatedItems = updateItemInArray(
|
||||
prev.items || [],
|
||||
|
||||
@@ -519,6 +519,28 @@ export const applyRatingOptimisticUpdates = (
|
||||
}
|
||||
});
|
||||
|
||||
const songListQueryKey = queryKeys.songs.list(variables.apiClientProps.serverId);
|
||||
const songListQueries = queryClient.getQueriesData({
|
||||
exact: false,
|
||||
queryKey: songListQueryKey,
|
||||
});
|
||||
|
||||
songListQueries.forEach(([queryKey, data]) => {
|
||||
if (data) {
|
||||
pendingUpdates.push({
|
||||
previousData: data,
|
||||
queryKey,
|
||||
updater: (prev: undefined | { items: Song[] }) => {
|
||||
if (!prev) return prev;
|
||||
const updatedItems = updateItemInArray(prev.items, itemIdSet, (item) =>
|
||||
createRatingUpdater<Song>(item),
|
||||
);
|
||||
return updatedItems ? { ...prev, items: updatedItems } : prev;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const topSongsQueryKey = queryKeys.albumArtists.topSongs(
|
||||
variables.apiClientProps.serverId,
|
||||
);
|
||||
@@ -652,6 +674,7 @@ export const applyRatingOptimisticUpdatesDeferred = (
|
||||
queryKeys.songs.detail(variables.apiClientProps.serverId),
|
||||
'song-detail',
|
||||
);
|
||||
collectQueries(queryKeys.songs.list(variables.apiClientProps.serverId), 'song-list');
|
||||
collectQueries(
|
||||
queryKeys.albumArtists.topSongs(variables.apiClientProps.serverId),
|
||||
'top-songs',
|
||||
@@ -712,6 +735,7 @@ export const applyRatingOptimisticUpdatesDeferred = (
|
||||
case 'album-artist-list':
|
||||
case 'album-list':
|
||||
case 'artist-list':
|
||||
case 'song-list':
|
||||
case 'top-songs': {
|
||||
const updatedItems = updateItemInArray(
|
||||
prev.items || [],
|
||||
|
||||
Reference in New Issue
Block a user