removed file from query when overwriting
This commit is contained in:
parent
9336aa287e
commit
ca9bee8222
1 changed files with 12 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
Cloud,
|
Cloud,
|
||||||
|
|
@ -26,6 +27,7 @@ import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { useTask } from "@/contexts/task-context";
|
import { useTask } from "@/contexts/task-context";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { File as SearchFile } from "@/src/app/api/queries/useGetSearchQuery";
|
||||||
|
|
||||||
interface KnowledgeDropdownProps {
|
interface KnowledgeDropdownProps {
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
|
|
@ -38,6 +40,7 @@ export function KnowledgeDropdown({
|
||||||
}: KnowledgeDropdownProps) {
|
}: KnowledgeDropdownProps) {
|
||||||
const { addTask } = useTask();
|
const { addTask } = useTask();
|
||||||
const { refetch: refetchTasks } = useGetTasksQuery();
|
const { refetch: refetchTasks } = useGetTasksQuery();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [showFolderDialog, setShowFolderDialog] = useState(false);
|
const [showFolderDialog, setShowFolderDialog] = useState(false);
|
||||||
|
|
@ -326,6 +329,15 @@ export function KnowledgeDropdown({
|
||||||
|
|
||||||
const handleOverwriteFile = async () => {
|
const handleOverwriteFile = async () => {
|
||||||
if (pendingFile) {
|
if (pendingFile) {
|
||||||
|
// Remove the old file from all search query caches before overwriting
|
||||||
|
queryClient.setQueriesData({ queryKey: ["search"] }, (oldData: []) => {
|
||||||
|
if (!oldData) return oldData;
|
||||||
|
// Filter out the file that's being overwritten
|
||||||
|
return oldData.filter(
|
||||||
|
(file: SearchFile) => file.filename !== pendingFile.name,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
await uploadFile(pendingFile, true);
|
await uploadFile(pendingFile, true);
|
||||||
setPendingFile(null);
|
setPendingFile(null);
|
||||||
setDuplicateFilename("");
|
setDuplicateFilename("");
|
||||||
|
|
@ -676,7 +688,6 @@ export function KnowledgeDropdown({
|
||||||
<DuplicateHandlingDialog
|
<DuplicateHandlingDialog
|
||||||
open={showDuplicateDialog}
|
open={showDuplicateDialog}
|
||||||
onOpenChange={setShowDuplicateDialog}
|
onOpenChange={setShowDuplicateDialog}
|
||||||
filename={duplicateFilename}
|
|
||||||
onOverwrite={handleOverwriteFile}
|
onOverwrite={handleOverwriteFile}
|
||||||
isLoading={fileUploading}
|
isLoading={fileUploading}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue