mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-17 14:10:14 +02:00
add optimistic update for top songs list (#1414)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
PlaylistSongListResponse,
|
PlaylistSongListResponse,
|
||||||
Song,
|
Song,
|
||||||
SongDetailResponse,
|
SongDetailResponse,
|
||||||
|
TopSongListResponse,
|
||||||
} from '/@/shared/types/domain-types';
|
} from '/@/shared/types/domain-types';
|
||||||
|
|
||||||
export interface PreviousQueryData {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
SetRatingArgs,
|
SetRatingArgs,
|
||||||
Song,
|
Song,
|
||||||
SongDetailResponse,
|
SongDetailResponse,
|
||||||
|
TopSongListResponse,
|
||||||
} from '/@/shared/types/domain-types';
|
} from '/@/shared/types/domain-types';
|
||||||
|
|
||||||
export const applyRatingOptimisticUpdates = (
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user