From 870e7dd3d352efb0512e48b54ab934ec8e9d9a41 Mon Sep 17 00:00:00 2001 From: dtoro Date: Thu, 9 Apr 2026 20:35:17 +0200 Subject: [PATCH] fix: refresh sidebar counts after photo mutations LIBRARY_STATS_QUERY_KEY was never invalidated by the bulk/single mutation paths in RightSidebar and PhotoInfoPanel, so the All Photos / Rated / Discarded / Tags badges only updated on reload. Add it to both shared invalidation helpers and the inline updateMutation, and correct the stale docstring on useLibraryStatsQuery. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/components/layout/RightSidebar.tsx | 2 ++ frontend/src/components/sidebar/PhotoInfoPanel.tsx | 3 +++ frontend/src/hooks/useLibraryStatsQuery.ts | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/layout/RightSidebar.tsx b/frontend/src/components/layout/RightSidebar.tsx index f966dbf..a485341 100644 --- a/frontend/src/components/layout/RightSidebar.tsx +++ b/frontend/src/components/layout/RightSidebar.tsx @@ -10,6 +10,7 @@ import { } from '../../services/api' import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery' import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery' +import { LIBRARY_STATS_QUERY_KEY } from '../../hooks/useLibraryStatsQuery' import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery' import { toast } from '../ToastContainer' import { PhotoInfoPanel } from '../sidebar/PhotoInfoPanel' @@ -32,6 +33,7 @@ export function RightSidebar({ onCollapse }: RightSidebarProps) { const invalidatePhotoQueries = () => { queryClient.invalidateQueries({ queryKey: ['photo'] }) queryClient.invalidateQueries({ queryKey: ['photos'] }) + queryClient.invalidateQueries({ queryKey: LIBRARY_STATS_QUERY_KEY }) } const bulkRatingMutation = useMutation({ diff --git a/frontend/src/components/sidebar/PhotoInfoPanel.tsx b/frontend/src/components/sidebar/PhotoInfoPanel.tsx index bed4880..3f1c51e 100644 --- a/frontend/src/components/sidebar/PhotoInfoPanel.tsx +++ b/frontend/src/components/sidebar/PhotoInfoPanel.tsx @@ -21,6 +21,7 @@ import { } from '../../services/api' import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery' import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery' +import { LIBRARY_STATS_QUERY_KEY } from '../../hooks/useLibraryStatsQuery' import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery' import { toast } from '../ToastContainer' import { @@ -147,6 +148,7 @@ export function PhotoInfoPanel({ photoId, darkTheme = false }: PhotoInfoPanelPro onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['photo', photoId] }) queryClient.invalidateQueries({ queryKey: ['photos'] }) + queryClient.invalidateQueries({ queryKey: LIBRARY_STATS_QUERY_KEY }) }, }) @@ -194,6 +196,7 @@ export function PhotoInfoPanel({ photoId, darkTheme = false }: PhotoInfoPanelPro queryClient.invalidateQueries({ queryKey: TAGS_QUERY_KEY }) queryClient.invalidateQueries({ queryKey: ['photo', photoId] }) queryClient.invalidateQueries({ queryKey: ['photos'] }) + queryClient.invalidateQueries({ queryKey: LIBRARY_STATS_QUERY_KEY }) } const addTagMutation = useMutation({ diff --git a/frontend/src/hooks/useLibraryStatsQuery.ts b/frontend/src/hooks/useLibraryStatsQuery.ts index 5078a03..db580cb 100644 --- a/frontend/src/hooks/useLibraryStatsQuery.ts +++ b/frontend/src/hooks/useLibraryStatsQuery.ts @@ -6,8 +6,9 @@ export const LIBRARY_STATS_QUERY_KEY = ['library', 'stats'] as const /** * Per-section counts for the LeftSidebar badges (All Photos, Rated, * Duplicates, Discarded). Cached briefly so navigating around doesn't - * re-fetch on every click; invalidated on photo mutations through the - * standard ['photos'] invalidation in the mutation onSuccess paths. + * re-fetch on every click. Mutations that change a photo's rating, + * discard flag, tags, etc. must invalidate LIBRARY_STATS_QUERY_KEY in + * their onSuccess so the badges stay live. */ export function useLibraryStatsQuery() { return useQuery({