From bce7a35f43198bcb8690dfd18b10fb7e683bab2d Mon Sep 17 00:00:00 2001 From: Eugen Ciur Date: Sat, 7 Sep 2024 09:58:59 +0200 Subject: [PATCH] WIP --- ui2/src/components/modals/DropFiles.tsx | 31 +++++++++++---------- ui2/src/features/nodes/apiSlice.ts | 36 ++----------------------- 2 files changed, 19 insertions(+), 48 deletions(-) diff --git a/ui2/src/components/modals/DropFiles.tsx b/ui2/src/components/modals/DropFiles.tsx index 0dde907a8..b40b6a781 100644 --- a/ui2/src/components/modals/DropFiles.tsx +++ b/ui2/src/components/modals/DropFiles.tsx @@ -1,13 +1,12 @@ -import {useContext, useState} from "react" +import {useState} from "react" import {Checkbox, Text} from "@mantine/core" import {Button, Modal, Container, Group, Loader} from "@mantine/core" import Error from "@/components/modals/Error" -import type {NodeType, FolderType} from "@/types" -import {store} from "@/app/store" +import type {FolderType} from "@/types" + import {uploadFile} from "@/slices/uploader" -import {nodeAdded} from "@/slices/dualPanel/dualPanel" -import PanelContext from "@/contexts/PanelContext" -import {useAddNewDocumentNodeMutation} from "@/features/nodes/apiSlice" +import {apiSlice} from "@/features/api/slice" +import {useAppDispatch} from "@/app/hooks" type Args = { opened: boolean @@ -27,23 +26,27 @@ export const DropFilesModal = ({ if (!source_files) { return } + const dispatch = useAppDispatch() const [error, setError] = useState("") const source_titles = [...source_files].map(n => n.name).join(", ") const target_title = target.title - const [addNewDocummentNode] = useAddNewDocumentNodeMutation() const localSubmit = async () => { for (let i = 0; i < source_files.length; i++) { - addNewDocummentNode({ - title: source_files[i].name, - ocr: false, - target: target, - ctype: "document" - }).then(() => { - console.log(`Node ${source_files[i].name} was created`) + dispatch( + uploadFile({ + file: source_files[i], + refreshTarget: true, + skipOCR: false, + target + }) + ).then(() => { + dispatch(apiSlice.util.invalidateTags(["Node"])) onSubmit() }) } + + return true } const localCancel = () => { diff --git a/ui2/src/features/nodes/apiSlice.ts b/ui2/src/features/nodes/apiSlice.ts index 7fb728305..2a3a15d57 100644 --- a/ui2/src/features/nodes/apiSlice.ts +++ b/ui2/src/features/nodes/apiSlice.ts @@ -12,11 +12,10 @@ type CreateFolderType = { ctype: "folder" } -type CreateDocumentNodeType = { - title: string +type CreateDocumentNodesType = { + source_files: File[] target: FolderType ocr: boolean - ctype: "document" } type RenameFolderType = { @@ -76,36 +75,6 @@ export const apiSliceWithNodes = apiSlice.injectEndpoints({ }), invalidatesTags: ["Node"] }), - addNewDocumentNode: builder.mutation({ - query: docData => ({ - url: "/nodes/", - method: "POST", - body: { - parent_id: docData.target.id, - title: docData.title, - ocr: docData.ocr, - ctype: "document" - } - }), - invalidatesTags: ["Node"], - async onQueryStarted(arg, {dispatch, queryFulfilled}) { - let itemData: UpdateFileStatusArg = { - item: { - source: null, - file_name: arg.title, - target: arg.target - }, - status: "uploading", - error: null - } - dispatch(uploaderFileItemAdded(itemData)) - try { - await queryFulfilled - } catch (err) { - dispatch(uploaderFileItemFailed(itemData)) - } - } - }), renameFolder: builder.mutation({ query: folder => ({ url: `/nodes/${folder.id}`, @@ -140,7 +109,6 @@ export const { useGetPaginatedNodesQuery, useGetFolderQuery, useAddNewFolderMutation, - useAddNewDocumentNodeMutation, useRenameFolderMutation, useUpdateNodeTagsMutation, useDeleteNodesMutation