mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
add optimistic update for top songs list (#1414)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
PlaylistSongListResponse,
|
||||
Song,
|
||||
SongDetailResponse,
|
||||
TopSongListResponse,
|
||||
} from '/@/shared/types/domain-types';
|
||||
|
||||
export interface PreviousQueryData {
|
||||
@@ -610,6 +611,40 @@ export const applyFavoriteOptimisticUpdates = (
|
||||
});
|
||||
}
|
||||
|
||||
const topSongsQueryKey = queryKeys.albumArtists.topSongs(
|
||||
variables.apiClientProps.serverId,
|
||||
);
|
||||
|
||||
const topSongsQueries = queryClient.getQueriesData({
|
||||
exact: false,
|
||||
queryKey: topSongsQueryKey,
|
||||
});
|
||||
|
||||
if (topSongsQueries.length) {
|
||||
topSongsQueries.forEach(([queryKey, data]) => {
|
||||
if (data) {
|
||||
previousQueries.push({ data, queryKey });
|
||||
queryClient.setQueryData(
|
||||
queryKey,
|
||||
(prev: TopSongListResponse | undefined) => {
|
||||
if (prev) {
|
||||
return {
|
||||
...prev,
|
||||
items: prev.items.map((item: Song) =>
|
||||
itemIdSet.has(item.id)
|
||||
? { ...item, userFavorite: isFavorite }
|
||||
: item,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return prev;
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
SetRatingArgs,
|
||||
Song,
|
||||
SongDetailResponse,
|
||||
TopSongListResponse,
|
||||
} from '/@/shared/types/domain-types';
|
||||
|
||||
export const applyRatingOptimisticUpdates = (
|
||||
@@ -495,6 +496,39 @@ export const applyRatingOptimisticUpdates = (
|
||||
});
|
||||
}
|
||||
|
||||
const topSongsQueryKey = queryKeys.albumArtists.topSongs(
|
||||
variables.apiClientProps.serverId,
|
||||
);
|
||||
|
||||
const topSongsQueries = queryClient.getQueriesData({
|
||||
exact: false,
|
||||
queryKey: topSongsQueryKey,
|
||||
});
|
||||
|
||||
if (topSongsQueries.length) {
|
||||
topSongsQueries.forEach(([queryKey, data]) => {
|
||||
if (data) {
|
||||
previousQueries.push({ data, queryKey });
|
||||
queryClient.setQueryData(
|
||||
queryKey,
|
||||
(prev: TopSongListResponse | undefined) => {
|
||||
if (prev) {
|
||||
return {
|
||||
...prev,
|
||||
items: prev.items.map((item: Song) =>
|
||||
itemIdSet.has(item.id)
|
||||
? { ...item, userRating: rating }
|
||||
: item,
|
||||
),
|
||||
};
|
||||
}
|
||||
return prev;
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user