mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
invalidate the album query on scrobble submission
This commit is contained in:
@@ -121,6 +121,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
event: 'timeupdate',
|
event: 'timeupdate',
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position,
|
position,
|
||||||
@@ -163,6 +164,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position,
|
position,
|
||||||
submission: true,
|
submission: true,
|
||||||
@@ -245,6 +247,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
event: 'start',
|
event: 'start',
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position: 0,
|
position: 0,
|
||||||
@@ -306,6 +309,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
event: 'timeupdate',
|
event: 'timeupdate',
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position,
|
position,
|
||||||
@@ -353,6 +357,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
event: 'pause',
|
event: 'pause',
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position,
|
position,
|
||||||
@@ -378,6 +383,7 @@ export const useScrobble = () => {
|
|||||||
{
|
{
|
||||||
apiClientProps: { serverId: currentSong._serverId || '' },
|
apiClientProps: { serverId: currentSong._serverId || '' },
|
||||||
query: {
|
query: {
|
||||||
|
albumId: currentSong.albumId,
|
||||||
event: 'unpause',
|
event: 'unpause',
|
||||||
id: currentSong.id,
|
id: currentSong.id,
|
||||||
position,
|
position,
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
|
|
||||||
import { api } from '/@/renderer/api';
|
import { api } from '/@/renderer/api';
|
||||||
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||||
import { incrementQueuePlayCount } from '/@/renderer/store/player.store';
|
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 queryClient = useQueryClient();
|
||||||
|
|
||||||
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,6 +21,15 @@ export const useSendScrobble = (options?: MutationOptions) => {
|
|||||||
// 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) {
|
||||||
incrementQueuePlayCount([variables.query.id]);
|
incrementQueuePlayCount([variables.query.id]);
|
||||||
|
|
||||||
|
// Invalidate the album detail query for the song's album
|
||||||
|
if (variables.query.albumId && variables.apiClientProps.serverId) {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: queryKeys.albums.detail(variables.apiClientProps.serverId, {
|
||||||
|
id: variables.query.albumId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -1237,6 +1237,7 @@ export type ScrobbleArgs = BaseEndpointArgs & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ScrobbleQuery = {
|
export type ScrobbleQuery = {
|
||||||
|
albumId?: string;
|
||||||
event?: 'pause' | 'start' | 'timeupdate' | 'unpause';
|
event?: 'pause' | 'start' | 'timeupdate' | 'unpause';
|
||||||
id: string;
|
id: string;
|
||||||
position?: number;
|
position?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user