From dc0550b112fac12aa975137c5e7c24689306bfab Mon Sep 17 00:00:00 2001 From: lideming Date: Thu, 30 May 2024 00:36:25 +0800 Subject: [PATCH] feat: right-click to open menu for document/collection links --- app/components/DocumentListItem.tsx | 8 ++++++++ .../Sidebar/components/CollectionLink.tsx | 12 +++++++++++- app/components/Sidebar/components/DocumentLink.tsx | 8 ++++++++ app/components/Sidebar/components/StarredLink.tsx | 14 +++++++++++++- app/menus/CollectionMenu.tsx | 8 ++++++++ app/menus/DocumentMenu.tsx | 8 ++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx index 999f28cb5..0f7a99ddd 100644 --- a/app/components/DocumentListItem.tsx +++ b/app/components/DocumentListItem.tsx @@ -81,6 +81,13 @@ function DocumentListItem( title: document.titleWithDefault, }, }} + onContextMenu={(e) => { + if (menuOpen) { + return; + } + e.preventDefault(); + handleMenuOpen(); + }} {...rest} > @@ -137,6 +144,7 @@ function DocumentListItem( = ({ return ( <> - + { + if (menuOpen || isEditing) { + return; + } + e.preventDefault(); + handleMenuOpen(); + }} + > = ({ onRename={() => editableTitleRef.current?.setIsEditing(true) } + visible={menuOpen} onOpen={handleMenuOpen} onClose={handleMenuClose} /> diff --git a/app/components/Sidebar/components/DocumentLink.tsx b/app/components/Sidebar/components/DocumentLink.tsx index 708e0cfe8..9b2d816fe 100644 --- a/app/components/Sidebar/components/DocumentLink.tsx +++ b/app/components/Sidebar/components/DocumentLink.tsx @@ -310,6 +310,13 @@ function InnerDocumentLink( $isDragging={isDragging} $isMoving={isMoving} onKeyDown={handleKeyDown} + onContextMenu={(e) => { + if (menuOpen || isEditing) { + return; + } + e.preventDefault(); + handleMenuOpen(); + }} >
@@ -372,6 +379,7 @@ function InnerDocumentLink( onRename={() => editableTitleRef.current?.setIsEditing(true) } + visible={menuOpen} onOpen={handleMenuOpen} onClose={handleMenuClose} /> diff --git a/app/components/Sidebar/components/StarredLink.tsx b/app/components/Sidebar/components/StarredLink.tsx index ee64fc63e..61b5a7f7c 100644 --- a/app/components/Sidebar/components/StarredLink.tsx +++ b/app/components/Sidebar/components/StarredLink.tsx @@ -115,7 +115,18 @@ function StarredLink({ star }: Props) { return ( <> - + { + if (menuOpen) { + return; + } + e.preventDefault(); + handleMenuOpen(); + }} + > diff --git a/app/menus/CollectionMenu.tsx b/app/menus/CollectionMenu.tsx index b8e0a4c27..2dea89b96 100644 --- a/app/menus/CollectionMenu.tsx +++ b/app/menus/CollectionMenu.tsx @@ -39,6 +39,7 @@ type Props = { collection: Collection; placement?: Placement; modal?: boolean; + visible?: boolean; label?: (props: MenuButtonHTMLProps) => React.ReactNode; onRename?: () => void; onOpen?: () => void; @@ -49,6 +50,7 @@ function CollectionMenu({ collection, label, modal = true, + visible, placement, onRename, onOpen, @@ -64,6 +66,12 @@ function CollectionMenu({ const history = useHistory(); const file = React.useRef(null); + React.useEffect(() => { + if (visible !== undefined && menu.visible !== visible) { + menu.setVisible(visible); + } + }, [visible]); + const handleExport = React.useCallback(() => { dialogs.openModal({ title: t("Export collection"), diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index 382e58d40..aa9800d79 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -61,6 +61,7 @@ type Props = { /** Pass true if the document is currently being displayed */ showDisplayOptions?: boolean; modal?: boolean; + visible?: boolean; showToggleEmbeds?: boolean; showPin?: boolean; label?: (props: MenuButtonHTMLProps) => React.ReactNode; @@ -74,6 +75,7 @@ function DocumentMenu({ document, className, modal = true, + visible, showToggleEmbeds, showDisplayOptions, label, @@ -106,6 +108,12 @@ function DocumentMenu({ }) ); + React.useEffect(() => { + if (visible !== undefined && menu.visible !== visible) { + menu.setVisible(visible); + } + }, [visible]); + const handleOpen = React.useCallback(async () => { if (!data && !loading) { await request();