Fix invalidation
This commit is contained in:
parent
c19522058a
commit
915fc9b1f1
1 changed files with 28 additions and 6 deletions
|
|
@ -1,4 +1,9 @@
|
|||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
QueryClient,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query";
|
||||
import { useSession } from "@ui/contexts/SessionContext";
|
||||
import { api } from "@ui/lib/api";
|
||||
import { toast } from "@ui/ui-library/toast/toast-queue";
|
||||
|
|
@ -154,6 +159,7 @@ export function useDownloadTabloFile() {
|
|||
// Hook to create a new file in a tablo
|
||||
export function useCreateTabloFile() {
|
||||
const { session } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
FileOperationResponse,
|
||||
|
|
@ -184,7 +190,6 @@ export function useCreateTabloFile() {
|
|||
},
|
||||
toastOptions
|
||||
);
|
||||
invalidateTabloData(variables.tabloId);
|
||||
},
|
||||
onError: (error, variables) => {
|
||||
toast.add(
|
||||
|
|
@ -196,12 +201,18 @@ export function useCreateTabloFile() {
|
|||
toastOptions
|
||||
);
|
||||
},
|
||||
onSettled: (_, _err, variables) => {
|
||||
if (variables) {
|
||||
invalidateTabloData(queryClient, variables.tabloId);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Hook to update an existing file in a tablo
|
||||
export function useUpdateTabloFile() {
|
||||
const { session } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
FileOperationResponse,
|
||||
|
|
@ -232,7 +243,6 @@ export function useUpdateTabloFile() {
|
|||
},
|
||||
toastOptions
|
||||
);
|
||||
invalidateTabloData(variables.tabloId);
|
||||
},
|
||||
onError: (error, variables) => {
|
||||
toast.add(
|
||||
|
|
@ -244,12 +254,18 @@ export function useUpdateTabloFile() {
|
|||
toastOptions
|
||||
);
|
||||
},
|
||||
onSettled: (_, _err, variables) => {
|
||||
if (variables) {
|
||||
invalidateTabloData(queryClient, variables.tabloId);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Hook to delete a file from a tablo
|
||||
export function useDeleteTabloFile() {
|
||||
const { session } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
FileOperationResponse,
|
||||
|
|
@ -279,7 +295,6 @@ export function useDeleteTabloFile() {
|
|||
},
|
||||
toastOptions
|
||||
);
|
||||
invalidateTabloData(variables.tabloId);
|
||||
},
|
||||
onError: (error, variables) => {
|
||||
toast.add(
|
||||
|
|
@ -291,12 +306,19 @@ export function useDeleteTabloFile() {
|
|||
toastOptions
|
||||
);
|
||||
},
|
||||
onSettled: (_, _err, variables) => {
|
||||
if (variables) {
|
||||
invalidateTabloData(queryClient, variables.tabloId);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Utility function to invalidate all tablo data queries for a specific tablo
|
||||
export const invalidateTabloData = (tabloId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
export const invalidateTabloData = (
|
||||
queryClient: QueryClient,
|
||||
tabloId: string
|
||||
) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["tablo-files", tabloId],
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue