mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
refactor: simplify keyboard shortcut implementation
- Remove unnecessary callback prop from NewDirectoryItemDropdown - Use atom directly in both components for cleaner code - Restore WithAtom wrapper for consistent pattern - Keep keyboard shortcut functionality intact Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -51,7 +51,7 @@ import { dragInfoAtom, newFileTypeAtom, openedFileAtom } from "./state"
|
|||||||
|
|
||||||
export function DirectoryPage() {
|
export function DirectoryPage() {
|
||||||
const { directory } = useContext(DirectoryPageContext)
|
const { directory } = useContext(DirectoryPageContext)
|
||||||
const [newFileType, setNewFileType] = useAtom(newFileTypeAtom)
|
const setNewFileType = useSetAtom(newFileTypeAtom)
|
||||||
const keyboardModifiers = useAtomValue(keyboardModifierAtom)
|
const keyboardModifiers = useAtomValue(keyboardModifierAtom)
|
||||||
|
|
||||||
// Keyboard shortcut handler for Cmd/Ctrl+Shift+N to create new directory
|
// Keyboard shortcut handler for Cmd/Ctrl+Shift+N to create new directory
|
||||||
@@ -76,7 +76,7 @@ export function DirectoryPage() {
|
|||||||
<header className="flex py-1 shrink-0 items-center gap-2 border-b px-4 w-full">
|
<header className="flex py-1 shrink-0 items-center gap-2 border-b px-4 w-full">
|
||||||
<FilePathBreadcrumb />
|
<FilePathBreadcrumb />
|
||||||
<div className="ml-auto flex flex-row gap-2">
|
<div className="ml-auto flex flex-row gap-2">
|
||||||
<NewDirectoryItemDropdown onNewDirectory={() => setNewFileType(FileType.Directory)} />
|
<NewDirectoryItemDropdown />
|
||||||
<UploadFileButton />
|
<UploadFileButton />
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -85,6 +85,8 @@ export function DirectoryPage() {
|
|||||||
</div>
|
</div>
|
||||||
<RenameFileDialog />
|
<RenameFileDialog />
|
||||||
<PreviewDialog />
|
<PreviewDialog />
|
||||||
|
<WithAtom atom={newFileTypeAtom}>
|
||||||
|
{(newFileType, setNewFileType) => (
|
||||||
<NewDirectoryDialog
|
<NewDirectoryDialog
|
||||||
open={newFileType === FileType.Directory}
|
open={newFileType === FileType.Directory}
|
||||||
directoryId={directory._id}
|
directoryId={directory._id}
|
||||||
@@ -94,6 +96,8 @@ export function DirectoryPage() {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
</WithAtom>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -227,11 +231,11 @@ function UploadFileButton() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function NewDirectoryItemDropdown({ onNewDirectory }: { onNewDirectory: () => void }) {
|
function NewDirectoryItemDropdown() {
|
||||||
const [newFileType] = useAtom(newFileTypeAtom)
|
const [newFileType, setNewFileType] = useAtom(newFileTypeAtom)
|
||||||
|
|
||||||
const addNewDirectory = () => {
|
const addNewDirectory = () => {
|
||||||
onNewDirectory()
|
setNewFileType(FileType.Directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCloseAutoFocus = (event: Event) => {
|
const handleCloseAutoFocus = (event: Event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user