(frontend) refresh the storage gauge on move and duplicate

Duplicating an item consumes storage and moving an item to or from the
root can change who owns its usage. Invalidate the entitlements cache
on success so the gauge reflects the new usage without a reload.
This commit is contained in:
Nathan Vasse
2026-07-23 17:08:12 +02:00
parent 826ad05ce6
commit d42dd3061a
2 changed files with 6 additions and 0 deletions
@@ -7,6 +7,7 @@ import {
ToasterItem,
} from "@/features/ui/components/toaster/Toaster";
import { useRemoveItemsFromPaginatedList } from "../hooks/useOptimisticPagination";
import { useRefreshEntitlementsQueryCache } from "../hooks/useRefreshItems";
import {
getMyFilesQueryKey,
getRecentItemsQueryKey,
@@ -25,6 +26,7 @@ export const useMoveItems = () => {
const driver = getDriver();
const removeItems = useRemoveItemsFromPaginatedList();
const refreshEntitlements = useRefreshEntitlementsQueryCache();
return useMutation({
mutationFn: async (payload: MoveItemPayload) => {
@@ -48,6 +50,7 @@ export const useMoveItems = () => {
queryClient.invalidateQueries({
queryKey: ["items", payload.parentId],
});
refreshEntitlements();
},
onError: (err, variables) => {
// If the mutation fails, you could invalidate to ensure fresh data
@@ -12,6 +12,7 @@ import {
useDeleteMutationCallbacks,
useRefreshItemCache,
useRefreshFavoriteCache,
useRefreshEntitlementsQueryCache,
} from "./useRefreshItems";
import { DefaultRoute } from "@/utils/defaultRoutes";
@@ -222,6 +223,7 @@ export const useMutationDuplicateItem = () => {
const { item } = useGlobalExplorer();
const refresh = useRefreshQueryCacheAfterMutation();
const refreshEntitlements = useRefreshEntitlementsQueryCache();
return useMutation({
mutationFn: (itemId: string) => {
@@ -230,6 +232,7 @@ export const useMutationDuplicateItem = () => {
onSuccess: () => {
const parentId = item?.originalId ?? item?.id;
refresh(parentId);
refreshEntitlements();
},
meta: {
// The caller already toasts a localized message on failure.