-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
import {useContext} from "react" | ||
import {useDisclosure} from "@mantine/hooks" | ||
import {Tooltip, ActionIcon} from "@mantine/core" | ||
import {IconFolderPlus} from "@tabler/icons-react" | ||
import {useSelector, useDispatch} from "react-redux" | ||
import {selectCurrentFolderID, folderAdded} from "@/slices/dualPanel/dualPanel" | ||
import create_new_folder from "@/components/modals/NewFolder" | ||
|
||
import {useSelector} from "react-redux" | ||
import {selectCurrentFolderID} from "@/slices/dualPanel/dualPanel" | ||
import {NewFolderModal} from "@/components/modals/NewFolder" | ||
import type {RootState} from "@/app/types" | ||
import type {NodeType, PanelMode} from "@/types" | ||
import type {PanelMode} from "@/types" | ||
|
||
import PanelContext from "@/contexts/PanelContext" | ||
|
||
export default function NewFolderButton() { | ||
const [opened, {open, close}] = useDisclosure(false) | ||
const mode: PanelMode = useContext(PanelContext) | ||
const dispatch = useDispatch() | ||
const currentFolderId = useSelector((state: RootState) => | ||
selectCurrentFolderID(state, mode) | ||
) | ||
|
||
const onNewFolder = () => { | ||
if (!currentFolderId) { | ||
console.error("Error: no current folder found") | ||
return | ||
} | ||
create_new_folder(currentFolderId).then((new_folder: NodeType) => { | ||
dispatch(folderAdded({node: new_folder, mode: mode})) | ||
}) | ||
} | ||
|
||
return ( | ||
<Tooltip label="New Folder" withArrow> | ||
<ActionIcon size={"lg"} variant="default" onClick={onNewFolder}> | ||
<IconFolderPlus stroke={1.4} /> | ||
</ActionIcon> | ||
</Tooltip> | ||
<> | ||
<Tooltip label="New Folder" withArrow> | ||
<ActionIcon size={"lg"} variant="default" onClick={open}> | ||
<IconFolderPlus stroke={1.4} /> | ||
</ActionIcon> | ||
</Tooltip> | ||
<NewFolderModal | ||
opened={opened} | ||
parent_id={currentFolderId!} | ||
onSubmit={close} | ||
onCancel={close} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters