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) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
} from '../../services/api'
|
} from '../../services/api'
|
||||||
import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery'
|
import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery'
|
||||||
import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery'
|
import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery'
|
||||||
|
import { LIBRARY_STATS_QUERY_KEY } from '../../hooks/useLibraryStatsQuery'
|
||||||
import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery'
|
import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery'
|
||||||
import { toast } from '../ToastContainer'
|
import { toast } from '../ToastContainer'
|
||||||
import { PhotoInfoPanel } from '../sidebar/PhotoInfoPanel'
|
import { PhotoInfoPanel } from '../sidebar/PhotoInfoPanel'
|
||||||
@@ -32,6 +33,7 @@ export function RightSidebar({ onCollapse }: RightSidebarProps) {
|
|||||||
const invalidatePhotoQueries = () => {
|
const invalidatePhotoQueries = () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ['photo'] })
|
queryClient.invalidateQueries({ queryKey: ['photo'] })
|
||||||
queryClient.invalidateQueries({ queryKey: ['photos'] })
|
queryClient.invalidateQueries({ queryKey: ['photos'] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: LIBRARY_STATS_QUERY_KEY })
|
||||||
}
|
}
|
||||||
|
|
||||||
const bulkRatingMutation = useMutation({
|
const bulkRatingMutation = useMutation({
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
} from '../../services/api'
|
} from '../../services/api'
|
||||||
import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery'
|
import { useActiveHeapMembers } from '../../hooks/useActiveHeapMembersQuery'
|
||||||
import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery'
|
import { HEAPS_QUERY_KEY } from '../../hooks/useHeapsQuery'
|
||||||
|
import { LIBRARY_STATS_QUERY_KEY } from '../../hooks/useLibraryStatsQuery'
|
||||||
import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery'
|
import { useTagsQuery, TAGS_QUERY_KEY } from '../../hooks/useTagsQuery'
|
||||||
import { toast } from '../ToastContainer'
|
import { toast } from '../ToastContainer'
|
||||||
import {
|
import {
|
||||||
@@ -147,6 +148,7 @@ export function PhotoInfoPanel({ photoId, darkTheme = false }: PhotoInfoPanelPro
|
|||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ['photo', photoId] })
|
queryClient.invalidateQueries({ queryKey: ['photo', photoId] })
|
||||||
queryClient.invalidateQueries({ queryKey: ['photos'] })
|
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: TAGS_QUERY_KEY })
|
||||||
queryClient.invalidateQueries({ queryKey: ['photo', photoId] })
|
queryClient.invalidateQueries({ queryKey: ['photo', photoId] })
|
||||||
queryClient.invalidateQueries({ queryKey: ['photos'] })
|
queryClient.invalidateQueries({ queryKey: ['photos'] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: LIBRARY_STATS_QUERY_KEY })
|
||||||
}
|
}
|
||||||
|
|
||||||
const addTagMutation = useMutation({
|
const addTagMutation = useMutation({
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ export const LIBRARY_STATS_QUERY_KEY = ['library', 'stats'] as const
|
|||||||
/**
|
/**
|
||||||
* Per-section counts for the LeftSidebar badges (All Photos, Rated,
|
* Per-section counts for the LeftSidebar badges (All Photos, Rated,
|
||||||
* Duplicates, Discarded). Cached briefly so navigating around doesn't
|
* Duplicates, Discarded). Cached briefly so navigating around doesn't
|
||||||
* re-fetch on every click; invalidated on photo mutations through the
|
* re-fetch on every click. Mutations that change a photo's rating,
|
||||||
* standard ['photos'] invalidation in the mutation onSuccess paths.
|
* discard flag, tags, etc. must invalidate LIBRARY_STATS_QUERY_KEY in
|
||||||
|
* their onSuccess so the badges stay live.
|
||||||
*/
|
*/
|
||||||
export function useLibraryStatsQuery() {
|
export function useLibraryStatsQuery() {
|
||||||
return useQuery<LibraryStats>({
|
return useQuery<LibraryStats>({
|
||||||
|
|||||||
Reference in New Issue
Block a user