mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
manually increment queue play count on scrobble
This commit is contained in:
@@ -3,11 +3,10 @@ import { AxiosError } from 'axios';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { incrementQueuePlayCount } from '/@/renderer/store/player.store';
|
||||
import { ScrobbleArgs, ScrobbleResponse } from '/@/shared/types/domain-types';
|
||||
|
||||
export const useSendScrobble = (options?: MutationOptions) => {
|
||||
// const incrementPlayCount = useIncrementQueuePlayCount();
|
||||
|
||||
return useMutation<ScrobbleResponse, AxiosError, ScrobbleArgs, null>({
|
||||
mutationFn: (args) => {
|
||||
return api.controller.scrobble({
|
||||
@@ -18,8 +17,7 @@ export const useSendScrobble = (options?: MutationOptions) => {
|
||||
onSuccess: (_data, variables) => {
|
||||
// Manually increment the play count for the song in the queue if scrobble was submitted
|
||||
if (variables.query.submission) {
|
||||
// incrementPlayCount([variables.query.id]);
|
||||
// sendPlayEvent(variables.query.id);
|
||||
incrementQueuePlayCount([variables.query.id]);
|
||||
}
|
||||
},
|
||||
...options,
|
||||
|
||||
@@ -2631,6 +2631,16 @@ export const updateQueueRatings = (ids: string[], rating: null | number) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const incrementQueuePlayCount = (ids: string[]) => {
|
||||
usePlayerStoreBase.setState((state) => {
|
||||
Object.values(state.queue.songs).forEach((song) => {
|
||||
if (ids.includes(song.id)) {
|
||||
song.playCount = (song.playCount || 0) + 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const usePlayerMuted = () => {
|
||||
return usePlayerStoreBase((state) => state.player.muted);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user