* feat: add status handling and visual indicators for file statuses * refactor: comment out status field and related rendering logic in SearchPage * format * add timeout on mutation delete document * make file fields be optional * fetch task files and display them on knowledge page * add tasks to files inside task context * added failed to status badge * added files on get all tasks on backend * Changed models to get parameters by settings if not existent * changed settings page to get models when is no ajth mode * fixed openai allowing validation even when value is not present * removed unused console log --------- Co-authored-by: Lucas Oliveira <lucas.edu.oli@hotmail.com> Co-authored-by: Mike Fortman <michael.fortman@datastax.com>
47 lines
1 KiB
TypeScript
47 lines
1 KiB
TypeScript
"use client";
|
|
|
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
interface DeleteDocumentRequest {
|
|
filename: string;
|
|
}
|
|
|
|
interface DeleteDocumentResponse {
|
|
success: boolean;
|
|
deleted_chunks: number;
|
|
filename: string;
|
|
message: string;
|
|
}
|
|
|
|
const deleteDocument = async (
|
|
data: DeleteDocumentRequest,
|
|
): Promise<DeleteDocumentResponse> => {
|
|
const response = await fetch("/api/documents/delete-by-filename", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(data),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json();
|
|
throw new Error(error.error || "Failed to delete document");
|
|
}
|
|
|
|
return response.json();
|
|
};
|
|
|
|
export const useDeleteDocument = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: deleteDocument,
|
|
onSettled: () => {
|
|
// Invalidate and refetch search queries to update the UI
|
|
setTimeout(() => {
|
|
queryClient.invalidateQueries({ queryKey: ["search"] });
|
|
}, 1000);
|
|
},
|
|
});
|
|
};
|