From 2827b2ae013ae219005146489937a7fc16d36c56 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 16 Jan 2026 04:23:57 -0800 Subject: [PATCH] invalidate the album query on scrobble submission --- src/renderer/features/player/hooks/use-scrobble.ts | 6 ++++++ .../features/player/mutations/scrobble-mutation.ts | 14 +++++++++++++- src/shared/types/domain-types.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/renderer/features/player/hooks/use-scrobble.ts b/src/renderer/features/player/hooks/use-scrobble.ts index 551419643..3084412a4 100644 --- a/src/renderer/features/player/hooks/use-scrobble.ts +++ b/src/renderer/features/player/hooks/use-scrobble.ts @@ -121,6 +121,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, event: 'timeupdate', id: currentSong.id, position, @@ -163,6 +164,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, id: currentSong.id, position, submission: true, @@ -245,6 +247,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, event: 'start', id: currentSong.id, position: 0, @@ -306,6 +309,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, event: 'timeupdate', id: currentSong.id, position, @@ -353,6 +357,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, event: 'pause', id: currentSong.id, position, @@ -378,6 +383,7 @@ export const useScrobble = () => { { apiClientProps: { serverId: currentSong._serverId || '' }, query: { + albumId: currentSong.albumId, event: 'unpause', id: currentSong.id, position, diff --git a/src/renderer/features/player/mutations/scrobble-mutation.ts b/src/renderer/features/player/mutations/scrobble-mutation.ts index 698461c9f..6381be4d8 100644 --- a/src/renderer/features/player/mutations/scrobble-mutation.ts +++ b/src/renderer/features/player/mutations/scrobble-mutation.ts @@ -1,12 +1,15 @@ -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { AxiosError } from 'axios'; import { api } from '/@/renderer/api'; +import { queryKeys } from '/@/renderer/api/query-keys'; 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 queryClient = useQueryClient(); + return useMutation({ mutationFn: (args) => { 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 if (variables.query.submission) { 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, diff --git a/src/shared/types/domain-types.ts b/src/shared/types/domain-types.ts index f1a6db8db..2be1d84fa 100644 --- a/src/shared/types/domain-types.ts +++ b/src/shared/types/domain-types.ts @@ -1237,6 +1237,7 @@ export type ScrobbleArgs = BaseEndpointArgs & { }; export type ScrobbleQuery = { + albumId?: string; event?: 'pause' | 'start' | 'timeupdate' | 'unpause'; id: string; position?: number;