fix: properly invalidate file resource when uploading and pinning finishes

This commit is contained in:
Juan Di Toro 2024-03-27 07:46:12 +01:00
parent 4cadd0072d
commit af9acd1bf7
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import { useSdk } from "~/components/lib/sdk-context";
import UppyFileUpload from "~/components/lib/uppy-file-upload"; import UppyFileUpload from "~/components/lib/uppy-file-upload";
import { PROTOCOL_S5, type Sdk } from "@lumeweb/portal-sdk"; import { PROTOCOL_S5, type Sdk } from "@lumeweb/portal-sdk";
import type { S5Client, HashProgressEvent } from "@lumeweb/s5-js"; import type { S5Client, HashProgressEvent } from "@lumeweb/s5-js";
import { useInvalidate } from "@refinedev/core";
const LISTENING_EVENTS = [ const LISTENING_EVENTS = [
"upload", "upload",
@ -27,6 +28,7 @@ const LISTENING_EVENTS = [
] as const; ] as const;
export function useUppy() { export function useUppy() {
const invalidate = useInvalidate()
const sdk = useSdk(); const sdk = useSdk();
const [uploadLimit, setUploadLimit] = useState<number>(0); const [uploadLimit, setUploadLimit] = useState<number>(0);
@ -200,6 +202,10 @@ export function useUppy() {
console.log("successful files:", result.successful); console.log("successful files:", result.successful);
console.log("failed files:", result.failed); console.log("failed files:", result.failed);
setFailedFiles(result.failed); setFailedFiles(result.failed);
invalidate({
resource: "file",
invalidates: ["list"]
})
}); });
const setStateCb = (event: (typeof LISTENING_EVENTS)[number]) => { const setStateCb = (event: (typeof LISTENING_EVENTS)[number]) => {

View File

@ -59,7 +59,7 @@ export const PinningProvider = ({ children }: React.PropsWithChildren) => {
) { ) {
const hasCompletedItems = queryResult.data.items.some(item => item.status === 'completed'); const hasCompletedItems = queryResult.data.items.some(item => item.status === 'completed');
if (hasCompletedItems) { if (hasCompletedItems) {
invalidate({ resource: "files", invalidates: ["list"] }); invalidate({ resource: "file", invalidates: ["list"] });
} }
} }
}, [ }, [