Skip to content

Commit

Permalink
Dran n drop file onto commander (for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Aug 20, 2024
1 parent 5e6c325 commit d92aaac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
21 changes: 21 additions & 0 deletions ui2/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# UI2

Server's REST API base url is read from `.env.development.local` file:

```
VITE_BASE_URL=http://localhost:8000/
```

In order to start in dev mode as user `admin` (without authentication)
use `VITE_REMOTE_USER` and `VITE_REMOTE_GROUPS` variables in .env.development.local` file:

```
VITE_REMOTE_USER=admin
VITE_REMOTE_GROUPS=admin
VITE_BASE_URL=http://localhost:8000/
```

Start in dev mode (on port 5173):

```
yarn dev
```
20 changes: 19 additions & 1 deletion ui2/src/components/Commander/Commander.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
selectPagination,
selectLastPageSize,
selectCurrentFolderID,
selectCurrentFolder,
selectCommanderPageSize,
selectCommanderPageNumber,
fetchPaginatedDocument
Expand All @@ -23,6 +24,7 @@ import type {NType, NodeType, PanelMode} from "@/types"
import Breadcrumbs from "@/components/Breadcrumbs"
import Pagination from "@/components/Pagination"
import PanelContext from "@/contexts/PanelContext"
import drop_files from "@/components/modals/DropFiles"
import {selectContentHeight} from "@/slices/sizes"
import classes from "./Commander.module.css"

Expand All @@ -40,6 +42,9 @@ export default function Commander() {
const currentNodeID = useSelector((state: RootState) =>
selectCurrentFolderID(state, mode)
)
const currentFolder = useSelector((state: RootState) =>
selectCurrentFolder(state, mode)
)
const pagination = useSelector((state: RootState) =>
selectPagination(state, mode)
)
Expand Down Expand Up @@ -127,14 +132,27 @@ export default function Commander() {
)
}
}
const onDragOver = (event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault()
console.log("something is being dragged over")
}

const onDrop = (event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault()

drop_files({
source_files: event.dataTransfer.files,
target: currentFolder!
}).then(() => {})
}

const nodes = data.map((n: NodeType) => (
<Node onClick={onClick} key={n.id} node={n} />
))

if (nodes.length > 0) {
return (
<div>
<div onDragOver={onDragOver} onDrop={onDrop}>
<FolderNodeActions />
<Breadcrumbs onClick={onClick} />
<Stack
Expand Down
2 changes: 1 addition & 1 deletion ui2/src/components/Commander/UploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function UploadButton() {
selectCurrentFolder(state, mode) as FolderType | undefined
)

const onUpload = (files: File[]) => {
const onUpload = (files: FileList) => {
if (!files) {
console.error("Empty array for uploaded files")
return
Expand Down
4 changes: 2 additions & 2 deletions ui2/src/components/modals/DropFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {nodeAdded} from "@/slices/dualPanel/dualPanel"
import PanelContext from "@/contexts/PanelContext"

type Args = {
source_files: File[]
source_files: FileList | File[]
target: FolderType
onOK: (node: NodeType) => void
onCancel: (msg?: string) => void
Expand Down Expand Up @@ -74,7 +74,7 @@ const DropFilesModal = ({source_files, target, onOK, onCancel}: Args) => {
}

type DropFileArgs = {
source_files: File[]
source_files: FileList | File[]
target: FolderType
}

Expand Down

0 comments on commit d92aaac

Please sign in to comment.