mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +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 { api } from '/@/renderer/api';
|
||||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||||
|
import { incrementQueuePlayCount } from '/@/renderer/store/player.store';
|
||||||
import { ScrobbleArgs, ScrobbleResponse } from '/@/shared/types/domain-types';
|
import { ScrobbleArgs, ScrobbleResponse } from '/@/shared/types/domain-types';
|
||||||
|
|
||||||
export const useSendScrobble = (options?: MutationOptions) => {
|
export const useSendScrobble = (options?: MutationOptions) => {
|
||||||
// const incrementPlayCount = useIncrementQueuePlayCount();
|
|
||||||
|
|
||||||
return useMutation<ScrobbleResponse, AxiosError, ScrobbleArgs, null>({
|
return useMutation<ScrobbleResponse, AxiosError, ScrobbleArgs, null>({
|
||||||
mutationFn: (args) => {
|
mutationFn: (args) => {
|
||||||
return api.controller.scrobble({
|
return api.controller.scrobble({
|
||||||
@@ -18,8 +17,7 @@ export const useSendScrobble = (options?: MutationOptions) => {
|
|||||||
onSuccess: (_data, variables) => {
|
onSuccess: (_data, variables) => {
|
||||||
// Manually increment the play count for the song in the queue if scrobble was submitted
|
// Manually increment the play count for the song in the queue if scrobble was submitted
|
||||||
if (variables.query.submission) {
|
if (variables.query.submission) {
|
||||||
// incrementPlayCount([variables.query.id]);
|
incrementQueuePlayCount([variables.query.id]);
|
||||||
// sendPlayEvent(variables.query.id);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...options,
|
...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 = () => {
|
export const usePlayerMuted = () => {
|
||||||
return usePlayerStoreBase((state) => state.player.muted);
|
return usePlayerStoreBase((state) => state.player.muted);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user