Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Sep 7, 2024
1 parent 355132f commit bce7a35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
31 changes: 17 additions & 14 deletions ui2/src/components/modals/DropFiles.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = () => {
Expand Down
36 changes: 2 additions & 34 deletions ui2/src/features/nodes/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -76,36 +75,6 @@ export const apiSliceWithNodes = apiSlice.injectEndpoints({
}),
invalidatesTags: ["Node"]
}),
addNewDocumentNode: builder.mutation<NodeType, CreateDocumentNodeType>({
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<NodeType, RenameFolderType>({
query: folder => ({
url: `/nodes/${folder.id}`,
Expand Down Expand Up @@ -140,7 +109,6 @@ export const {
useGetPaginatedNodesQuery,
useGetFolderQuery,
useAddNewFolderMutation,
useAddNewDocumentNodeMutation,
useRenameFolderMutation,
useUpdateNodeTagsMutation,
useDeleteNodesMutation
Expand Down

0 comments on commit bce7a35

Please sign in to comment.