mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
handle favorite/rating column mutations
This commit is contained in:
@@ -4,6 +4,7 @@ import isElectron from 'is-electron';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { eventEmitter } from '/@/renderer/events/event-emitter';
|
||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { useSetAlbumListItemDataById } from '/@/renderer/store';
|
||||
import { useFavoriteEvent } from '/@/renderer/store/event.store';
|
||||
@@ -31,6 +32,22 @@ export const useCreateFavorite = (args: MutationHookArgs) => {
|
||||
apiClientProps: { serverId: args.apiClientProps.serverId },
|
||||
});
|
||||
},
|
||||
onError: (_error, variables) => {
|
||||
eventEmitter.emit('USER_FAVORITE', {
|
||||
favorite: false,
|
||||
id: variables.query.id,
|
||||
itemType: variables.query.type,
|
||||
});
|
||||
},
|
||||
onMutate: (variables) => {
|
||||
eventEmitter.emit('USER_FAVORITE', {
|
||||
favorite: true,
|
||||
id: variables.query.id,
|
||||
itemType: variables.query.type,
|
||||
});
|
||||
|
||||
return null;
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
const { apiClientProps } = variables;
|
||||
const serverId = apiClientProps.serverId;
|
||||
|
||||
@@ -4,6 +4,7 @@ import isElectron from 'is-electron';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { eventEmitter } from '/@/renderer/events/event-emitter';
|
||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { useSetAlbumListItemDataById } from '/@/renderer/store';
|
||||
import { useFavoriteEvent } from '/@/renderer/store/event.store';
|
||||
@@ -31,6 +32,22 @@ export const useDeleteFavorite = (args: MutationHookArgs) => {
|
||||
apiClientProps: { serverId: args.apiClientProps.serverId },
|
||||
});
|
||||
},
|
||||
onError: (_error, variables) => {
|
||||
eventEmitter.emit('USER_FAVORITE', {
|
||||
favorite: true,
|
||||
id: variables.query.id,
|
||||
itemType: variables.query.type,
|
||||
});
|
||||
},
|
||||
onMutate: (variables) => {
|
||||
eventEmitter.emit('USER_FAVORITE', {
|
||||
favorite: false,
|
||||
id: variables.query.id,
|
||||
itemType: variables.query.type,
|
||||
});
|
||||
|
||||
return null;
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
const { apiClientProps } = variables;
|
||||
const serverId = apiClientProps.serverId;
|
||||
|
||||
@@ -4,6 +4,7 @@ import isElectron from 'is-electron';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { eventEmitter } from '/@/renderer/events/event-emitter';
|
||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { useSetAlbumListItemDataById } from '/@/renderer/store';
|
||||
import { useRatingEvent } from '/@/renderer/store/event.store';
|
||||
@@ -53,6 +54,12 @@ export const useSetRating = (args: MutationHookArgs) => {
|
||||
}
|
||||
},
|
||||
onMutate: (variables) => {
|
||||
eventEmitter.emit('USER_RATING', {
|
||||
id: variables.query.item.map((item) => item.id),
|
||||
itemType: variables.query.item[0].itemType,
|
||||
rating: variables.query.rating,
|
||||
});
|
||||
|
||||
const songIds: string[] = [];
|
||||
for (const item of variables.query.item) {
|
||||
switch (item.itemType) {
|
||||
|
||||
Reference in New Issue
Block a user