Procházet zdrojové kódy

feat(files): remove local addFile method and update upload form to invalidate files query on upload

vtugulan před 6 měsíci
rodič
revize
c909cf17fd
2 změnil soubory, kde provedl 6 přidání a 18 odebrání
  1. 0 17
      app/components/filesTable.tsx
  2. 6 1
      app/components/uploadForm.tsx

+ 0 - 17
app/components/filesTable.tsx

@@ -50,23 +50,6 @@ export function FilesTable({ onFileAdded }: FilesTableProps) {
     }
   }, [data]);
 
-  // Method to add a new file to the table
-  const addFile = (file: FileData) => {
-    setFiles(prevFiles => [file, ...prevFiles]);
-    // Call the onFileAdded prop if provided
-    if (onFileAdded) {
-      onFileAdded(file);
-    }
-  };
-
-  // Make addFile available globally for the upload form
-  useEffect(() => {
-    (window as any).addFileToTable = addFile;
-    return () => {
-      delete (window as any).addFileToTable;
-    };
-  }, [onFileAdded]);
-
   const columns: ColumnDef<FileData>[] = [
     {
       id: "select",

+ 6 - 1
app/components/uploadForm.tsx

@@ -1,6 +1,7 @@
 "use client";
 
 import { useState } from "react";
+import { useQueryClient } from "@tanstack/react-query";
 
 interface FileData {
   id: string;
@@ -13,6 +14,7 @@ interface FileData {
 
 export const UploadForm = ({ onFileUploaded }: { onFileUploaded?: (file: FileData) => void }) => {
   const [isUploading, setIsUploading] = useState(false);
+  const queryClient = useQueryClient();
 
   const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
     if (e.target.files && e.target.files[0]) {
@@ -30,7 +32,10 @@ export const UploadForm = ({ onFileUploaded }: { onFileUploaded?: (file: FileDat
         const result = await response.json();
         
         if (result.success) {
-          // Call the callback to add the new file to the table
+          // Invalidate the files query to trigger a refresh
+          await queryClient.invalidateQueries({ queryKey: ["files"] });
+          
+          // Call the callback if provided
           if (onFileUploaded) {
             onFileUploaded(result.file);
           }