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() {
|
||||
const { directory } = useContext(DirectoryPageContext)
|
||||
const [newFileType, setNewFileType] = useAtom(newFileTypeAtom)
|
||||
const setNewFileType = useSetAtom(newFileTypeAtom)
|
||||
const keyboardModifiers = useAtomValue(keyboardModifierAtom)
|
||||
|
||||
// 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">
|
||||
<FilePathBreadcrumb />
|
||||
<div className="ml-auto flex flex-row gap-2">
|
||||
<NewDirectoryItemDropdown onNewDirectory={() => setNewFileType(FileType.Directory)} />
|
||||
<NewDirectoryItemDropdown />
|
||||
<UploadFileButton />
|
||||
</div>
|
||||
</header>
|
||||
@@ -85,6 +85,8 @@ export function DirectoryPage() {
|
||||
</div>
|
||||
<RenameFileDialog />
|
||||
<PreviewDialog />
|
||||
<WithAtom atom={newFileTypeAtom}>
|
||||
{(newFileType, setNewFileType) => (
|
||||
<NewDirectoryDialog
|
||||
open={newFileType === FileType.Directory}
|
||||
directoryId={directory._id}
|
||||
@@ -94,6 +96,8 @@ export function DirectoryPage() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</WithAtom>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -227,11 +231,11 @@ function UploadFileButton() {
|
||||
)
|
||||
}
|
||||
|
||||
function NewDirectoryItemDropdown({ onNewDirectory }: { onNewDirectory: () => void }) {
|
||||
const [newFileType] = useAtom(newFileTypeAtom)
|
||||
function NewDirectoryItemDropdown() {
|
||||
const [newFileType, setNewFileType] = useAtom(newFileTypeAtom)
|
||||
|
||||
const addNewDirectory = () => {
|
||||
onNewDirectory()
|
||||
setNewFileType(FileType.Directory)
|
||||
}
|
||||
|
||||
const handleCloseAutoFocus = (event: Event) => {
|
||||
|
||||
Reference in New Issue
Block a user