|
1 | | -import React, { useEffect, useState } from "react"; |
| 1 | +import React, { useEffect, useRef, useState } from "react"; |
2 | 2 | import { ReactComponent as FolderIcon } from "../../assets/icons/folder-icon.svg"; |
3 | 3 |
|
4 | | -import useLocalFS, { |
5 | | - FSDirectory, |
6 | | - FSObject, |
7 | | - isFSDirectory, |
8 | | -} from "../../stores/localFS"; |
| 4 | +import { FSDirectory, FSObject, isFSDirectory } from "../../stores/localFS"; |
9 | 5 | import useLocalFSWithHistory from "../../hooks/useLocalFSWithHistory"; |
10 | 6 |
|
11 | 7 | import "./FileBrowser.scss"; |
12 | 8 | import AppSideBar from "../../components/AppSideBar"; |
13 | | -import useCompression from "../../hooks/useCompression"; |
| 9 | +import ContextMenu from "../../ContextMenu/ContextMenu"; |
| 10 | +import { getMainContentContextItems } from "./contextMenus"; |
14 | 11 | const defaultPath = "/home/user"; |
15 | 12 |
|
16 | 13 | interface FileBrowserProps { |
@@ -64,20 +61,28 @@ interface MainContentProps { |
64 | 61 |
|
65 | 62 | function MainContent({ currentDirectory, openFSObject }: MainContentProps) { |
66 | 63 | const [selected, setSelected] = useState<string>(""); |
67 | | - const fs = useLocalFS(); |
68 | | - const { compress } = useCompression(); |
| 64 | + const clickPosition = useRef<{ x: number; y: number }>({ x: 0, y: 0 }); |
| 65 | + const [open, setOpen] = useState(false); |
69 | 66 |
|
70 | 67 | function handleRightClick(e: React.MouseEvent) { |
| 68 | + clickPosition.current = { x: e.clientX, y: e.clientY }; |
71 | 69 | e.stopPropagation(); |
72 | 70 | e.preventDefault(); |
73 | | - //fs.createFile("test-create-file.txt", currentDirectory, compress("Hello world!")); |
| 71 | + setOpen(true); |
74 | 72 | } |
75 | 73 |
|
76 | 74 | return ( |
77 | 75 | <div |
78 | 76 | className="file-browser__main-content" |
79 | 77 | onContextMenu={handleRightClick} |
80 | 78 | > |
| 79 | + {open && ( |
| 80 | + <ContextMenu |
| 81 | + position={clickPosition.current} |
| 82 | + items={getMainContentContextItems()} |
| 83 | + close={() => setOpen(!open)} |
| 84 | + /> |
| 85 | + )} |
81 | 86 | {Object.values<FSObject>(currentDirectory.contents).map((fsObject) => ( |
82 | 87 | <DirectoryOrFile |
83 | 88 | fsObject={fsObject} |
|
0 commit comments