From 7638bdf171ead3b8ac268bf79d9f2275af6ecb42 Mon Sep 17 00:00:00 2001 From: "Ton Hoang Nguyen (Bill)" <32552798+HahaBill@users.noreply.github.com> Date: Sat, 16 Mar 2024 09:16:42 +0000 Subject: [PATCH] Desktop: Resolves #9984: Allow 'All Notes' to have 'Toggle own sort order' (#10021) Co-authored-by: Laurent Cozic --- packages/app-desktop/gui/Sidebar/Sidebar.tsx | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/app-desktop/gui/Sidebar/Sidebar.tsx b/packages/app-desktop/gui/Sidebar/Sidebar.tsx index 8cb7ae3f9..80008a28c 100644 --- a/packages/app-desktop/gui/Sidebar/Sidebar.tsx +++ b/packages/app-desktop/gui/Sidebar/Sidebar.tsx @@ -468,12 +468,13 @@ const SidebarComponent = (props: Props) => { Setting.setValue(key === 'tagHeader' ? 'tagHeaderIsExpanded' : 'folderHeaderIsExpanded', !isExpanded); }, [props.folderHeaderIsExpanded, props.tagHeaderIsExpanded]); - const onAllNotesClick_ = () => { + const onAllNotesClick_ = useCallback(() => { props.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID, }); - }; + folderItem_click(ALL_NOTES_FILTER_ID); + }, [props.dispatch, folderItem_click]); const anchorItemRef = (type: string, id: string) => { if (!anchorItemRefs.current[type]) anchorItemRefs.current[type] = {}; @@ -492,6 +493,20 @@ const SidebarComponent = (props: Props) => { return ; }; + const toggleAllNotesContextMenu = useCallback(() => { + const menu = new Menu(); + + if (Setting.value('notes.perFolderSortOrderEnabled')) { + menu.append(new MenuItem({ + ...menuUtils.commandToStatefulMenuItem('togglePerFolderSortOrder', ALL_NOTES_FILTER_ID), + type: 'checkbox', + checked: PerFolderSortOrderService.isSet(ALL_NOTES_FILTER_ID), + })); + } + + menu.popup({ window: bridge().window() }); + }, []); + const renderAllNotesItem = (theme: Theme, selected: boolean) => { return ( @@ -503,6 +518,7 @@ const SidebarComponent = (props: Props) => { href="#" selected={selected} onClick={onAllNotesClick_} + onContextMenu={toggleAllNotesContextMenu} > {_('All notes')} @@ -728,7 +744,7 @@ const SidebarComponent = (props: Props) => { if (props.folders.length) { - const allNotesSelected = props.notesParentType === 'SmartFilter' && props.selectedSmartFilterId === ALL_NOTES_FILTER_ID; + const allNotesSelected = props.selectedFolderId === ALL_NOTES_FILTER_ID; const result = renderFolders(props, renderFolderItem); const folderItems = [renderAllNotesItem(theme, allNotesSelected)].concat(result.items); folderItemsOrder_.current = result.order;