mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 18:33:33 +00:00
[slightly less scuffed bugfix]: Update table rating/favorite when updated anywhere … (#707)
* [scuffed bugfix]: Update table rating/favorite when updated anywhere else Modify player store to have temporary state for favorite/rating update Add effect handler for `virtual-table` to update rating/favorite for players Note that this does not handle song grid view. Using a similar handler for gird view did not work, as it appeared to result in inconsistent state. Finally, this is probably not the optimal solution. Performance appears fine for ~20k items, but no guarantees. * restore should update song * update song rating/favorite/played everywhere except playlist * special rule for playlists * use iterator instead
This commit is contained in:
parent
9d44f0fc08
commit
56c229a5e0
18 changed files with 223 additions and 143 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useSetAlbumListItemDataById, useSetQueueFavorite } from '/@/renderer/store';
|
||||
import isElectron from 'is-electron';
|
||||
import { useFavoriteEvent } from '/@/renderer/store/event.store';
|
||||
|
||||
const remote = isElectron() ? window.electron.remote : null;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ export const useCreateFavorite = (args: MutationHookArgs) => {
|
|||
const queryClient = useQueryClient();
|
||||
const setAlbumListData = useSetAlbumListItemDataById();
|
||||
const setQueueFavorite = useSetQueueFavorite();
|
||||
const setFavoriteEvent = useFavoriteEvent();
|
||||
|
||||
return useMutation<
|
||||
FavoriteResponse,
|
||||
|
|
@ -47,6 +49,7 @@ export const useCreateFavorite = (args: MutationHookArgs) => {
|
|||
if (variables.query.type === LibraryItem.SONG) {
|
||||
remote?.updateFavorite(true, serverId, variables.query.id);
|
||||
setQueueFavorite(variables.query.id, true);
|
||||
setFavoriteEvent(variables.query.id, true);
|
||||
}
|
||||
|
||||
// We only need to set if we're already on the album detail page
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useSetAlbumListItemDataById, useSetQueueFavorite } from '/@/renderer/store';
|
||||
import isElectron from 'is-electron';
|
||||
import { useFavoriteEvent } from '/@/renderer/store/event.store';
|
||||
|
||||
const remote = isElectron() ? window.electron.remote : null;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ export const useDeleteFavorite = (args: MutationHookArgs) => {
|
|||
const queryClient = useQueryClient();
|
||||
const setAlbumListData = useSetAlbumListItemDataById();
|
||||
const setQueueFavorite = useSetQueueFavorite();
|
||||
const setFavoriteEvent = useFavoriteEvent();
|
||||
|
||||
return useMutation<
|
||||
FavoriteResponse,
|
||||
|
|
@ -47,6 +49,7 @@ export const useDeleteFavorite = (args: MutationHookArgs) => {
|
|||
if (variables.query.type === LibraryItem.SONG) {
|
||||
remote?.updateFavorite(false, serverId, variables.query.id);
|
||||
setQueueFavorite(variables.query.id, false);
|
||||
setFavoriteEvent(variables.query.id, false);
|
||||
}
|
||||
|
||||
// We only need to set if we're already on the album detail page
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useSetAlbumListItemDataById, useSetQueueRating } from '/@/renderer/store';
|
||||
import isElectron from 'is-electron';
|
||||
import { useRatingEvent } from '/@/renderer/store/event.store';
|
||||
|
||||
const remote = isElectron() ? window.electron.remote : null;
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ export const useSetRating = (args: MutationHookArgs) => {
|
|||
const queryClient = useQueryClient();
|
||||
const setAlbumListData = useSetAlbumListItemDataById();
|
||||
const setQueueRating = useSetQueueRating();
|
||||
const setRatingEvent = useRatingEvent();
|
||||
|
||||
return useMutation<
|
||||
RatingResponse,
|
||||
|
|
@ -43,25 +45,36 @@ export const useSetRating = (args: MutationHookArgs) => {
|
|||
break;
|
||||
case LibraryItem.SONG:
|
||||
setQueueRating([item.id], item.userRating);
|
||||
setRatingEvent([item.id], item.userRating);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
onMutate: (variables) => {
|
||||
const songIds: string[] = [];
|
||||
for (const item of variables.query.item) {
|
||||
switch (item.itemType) {
|
||||
case LibraryItem.ALBUM:
|
||||
setAlbumListData(item.id, { userRating: variables.query.rating });
|
||||
break;
|
||||
case LibraryItem.SONG:
|
||||
setQueueRating([item.id], variables.query.rating);
|
||||
songIds.push(item.id);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (songIds.length > 0) {
|
||||
setQueueRating(songIds, variables.query.rating);
|
||||
setRatingEvent(songIds, variables.query.rating);
|
||||
}
|
||||
|
||||
if (remote) {
|
||||
const ids = variables.query.item.map((item) => item.id);
|
||||
remote.updateRating(variables.query.rating, variables.query.item[0].serverId, ids);
|
||||
remote.updateRating(
|
||||
variables.query.rating,
|
||||
variables.query.item[0].serverId,
|
||||
songIds,
|
||||
);
|
||||
}
|
||||
|
||||
return { previous: { items: variables.query.item } };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue