|
|
@@ -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);
|
|
|
}
|