mirror of
https://github.com/suitenumerique/drive.git
synced 2026-08-17 20:15:40 +02:00
✨(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:
@@ -7,6 +7,7 @@ import {
|
|||||||
ToasterItem,
|
ToasterItem,
|
||||||
} from "@/features/ui/components/toaster/Toaster";
|
} from "@/features/ui/components/toaster/Toaster";
|
||||||
import { useRemoveItemsFromPaginatedList } from "../hooks/useOptimisticPagination";
|
import { useRemoveItemsFromPaginatedList } from "../hooks/useOptimisticPagination";
|
||||||
|
import { useRefreshEntitlementsQueryCache } from "../hooks/useRefreshItems";
|
||||||
import {
|
import {
|
||||||
getMyFilesQueryKey,
|
getMyFilesQueryKey,
|
||||||
getRecentItemsQueryKey,
|
getRecentItemsQueryKey,
|
||||||
@@ -25,6 +26,7 @@ export const useMoveItems = () => {
|
|||||||
const driver = getDriver();
|
const driver = getDriver();
|
||||||
|
|
||||||
const removeItems = useRemoveItemsFromPaginatedList();
|
const removeItems = useRemoveItemsFromPaginatedList();
|
||||||
|
const refreshEntitlements = useRefreshEntitlementsQueryCache();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (payload: MoveItemPayload) => {
|
mutationFn: async (payload: MoveItemPayload) => {
|
||||||
@@ -48,6 +50,7 @@ export const useMoveItems = () => {
|
|||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["items", payload.parentId],
|
queryKey: ["items", payload.parentId],
|
||||||
});
|
});
|
||||||
|
refreshEntitlements();
|
||||||
},
|
},
|
||||||
onError: (err, variables) => {
|
onError: (err, variables) => {
|
||||||
// If the mutation fails, you could invalidate to ensure fresh data
|
// If the mutation fails, you could invalidate to ensure fresh data
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
useDeleteMutationCallbacks,
|
useDeleteMutationCallbacks,
|
||||||
useRefreshItemCache,
|
useRefreshItemCache,
|
||||||
useRefreshFavoriteCache,
|
useRefreshFavoriteCache,
|
||||||
|
useRefreshEntitlementsQueryCache,
|
||||||
} from "./useRefreshItems";
|
} from "./useRefreshItems";
|
||||||
import { DefaultRoute } from "@/utils/defaultRoutes";
|
import { DefaultRoute } from "@/utils/defaultRoutes";
|
||||||
|
|
||||||
@@ -222,6 +223,7 @@ export const useMutationDuplicateItem = () => {
|
|||||||
const { item } = useGlobalExplorer();
|
const { item } = useGlobalExplorer();
|
||||||
|
|
||||||
const refresh = useRefreshQueryCacheAfterMutation();
|
const refresh = useRefreshQueryCacheAfterMutation();
|
||||||
|
const refreshEntitlements = useRefreshEntitlementsQueryCache();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (itemId: string) => {
|
mutationFn: (itemId: string) => {
|
||||||
@@ -230,6 +232,7 @@ export const useMutationDuplicateItem = () => {
|
|||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
const parentId = item?.originalId ?? item?.id;
|
const parentId = item?.originalId ?? item?.id;
|
||||||
refresh(parentId);
|
refresh(parentId);
|
||||||
|
refreshEntitlements();
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
// The caller already toasts a localized message on failure.
|
// The caller already toasts a localized message on failure.
|
||||||
|
|||||||
Reference in New Issue
Block a user