Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(mobile): open the global menu on a strip of cards
Elian Doran26fb8b8dc545
diff --git a/apps/client/src/widgets/buttons/global_menu.css b/apps/client/src/widgets/buttons/global_menu.cssindex 9d64d52745..d78b9c77ad 100644--- a/apps/client/src/widgets/buttons/global_menu.css+++ b/apps/client/src/widgets/buttons/global_menu.css@@ -8,6 +8,12 @@min-width: 20em;}+.tn-menu-actions.global-menu-strip {+ display: grid;+ grid-auto-flow: column;+ grid-auto-columns: 1fr;+}+button.global-menu-button {--update-badge-x-offset: 4%;--update-badge-y-offset: -16%;diff --git a/apps/client/src/widgets/buttons/global_menu.spec.tsx b/apps/client/src/widgets/buttons/global_menu.spec.tsxindex d2763f6063..aaabdc2065 100644--- a/apps/client/src/widgets/buttons/global_menu.spec.tsx+++ b/apps/client/src/widgets/buttons/global_menu.spec.tsx@@ -312,12 +312,16 @@ describe("GlobalMenu", () => {expect([ ...topLevel, ...advanced ].some((row) => row?.startsWith("global_menu.show-cheatsheet"))).toBe(false);});- it("pairs the history views, and fullscreen with Zen mode, on a phone, and keeps them as rows elsewhere", async () => {+ it("opens a phone's menu on a strip of search and the history views, and pairs fullscreen with Zen mode", async () => {+ const stripOf = (scope: Element | null | undefined) => [ ...scope?.querySelectorAll(":scope > .tn-menu-actions > .tn-menu-action") ?? [] ]+ .map((tile) => tile.textContent?.trim());const pairsOf = (scope: Element | null | undefined) => [ ...scope?.querySelectorAll(":scope > .form-list-row") ?? [] ].map((row) => [ ...row.querySelectorAll(":scope > .form-list-col") ].map((col) => col.textContent?.trim()));- const pairedKeys = [ "recent_changes.title", "global_menu.show_deleted_notes", "global_menu.toggle_fullscreen", "global_menu.toggle-zen-mode" ];+ const movedKeys = [ "global_menu.search_notes", "recent_changes.title", "global_menu.show_deleted_notes",+ "global_menu.toggle_fullscreen", "global_menu.toggle-zen-mode" ];const desktop = await openSubmenu("global_menu.advanced");+ expect(stripOf(desktop.topLevelScroll)).toEqual([]);expect(pairsOf(desktop.topLevelScroll)).toEqual([]);expect(desktop.topLevel).toContain("global_menu.show_deleted_notes");expect(desktop.topLevel).toContain("global_menu.toggle_fullscreen");@@ -326,12 +330,11 @@ describe("GlobalMenu", () => {ctrl.mobile = true;const phone = await openSubmenu("global_menu.advanced");- expect(phone.topLevel[0]).toBe("global_menu.search_notes");- expect(pairsOf(phone.topLevelScroll)).toEqual([- [ "recent_changes.title", "global_menu.show_deleted_notes" ],- [ "global_menu.fullscreen", "global_menu.toggle-zen-mode" ]- ]);- for (const key of pairedKeys) {+ const strip = phone.topLevelScroll?.firstElementChild;+ expect(strip?.classList.contains("tn-menu-actions-cards")).toBe(true);+ expect(stripOf(phone.topLevelScroll)).toEqual([ "global_menu.search_notes", "recent_changes.title", "global_menu.show_deleted_notes" ]);+ expect(pairsOf(phone.topLevelScroll)).toEqual([ [ "global_menu.fullscreen", "global_menu.toggle-zen-mode" ] ]);+ for (const key of movedKeys) {expect(phone.topLevel.some((row) => row?.startsWith(key))).toBe(false);}});diff --git a/apps/client/src/widgets/buttons/global_menu.tsx b/apps/client/src/widgets/buttons/global_menu.tsxindex 6fcd5ba9c5..c27312effe 100644--- a/apps/client/src/widgets/buttons/global_menu.tsx+++ b/apps/client/src/widgets/buttons/global_menu.tsx@@ -6,6 +6,7 @@ import { useContext, useEffect, useRef, useState } from "preact/hooks";import { CommandNames } from "../../components/app_context";import Component from "../../components/component";+import type { MenuCommandItem } from "../../menus/context_menu";import {COLOR_SCHEME_CYCLE, COLOR_SCHEME_ICONS, ColorScheme, resolveColorScheme, THEME_FAMILY_SCHEMES} from "../../services/color_scheme";@@ -17,6 +18,7 @@ import {useStaticTooltip, useStaticTooltipWithKeyboardShortcut, useTriliumOption, useTriliumOptionBool,useUserThemes} from "../react/hooks";+import { MenuItemRows } from "../react/Menu";import { ParentComponent } from "../react/react_utils";interface MenuItemProps<T> {@@ -36,6 +38,15 @@ export default function GlobalMenu({ isHorizontalLayout }: { isHorizontalLayout:const { isUpdateAvailable, latestVersion } = useTriliumUpdateStatus();const logoRef = useRef<SVGSVGElement>(null);useStaticTooltip(logoRef);+ const commandAction = (command: CommandNames, uiIcon: string, title: string): MenuCommandItem<CommandNames> => ({+ title, uiIcon, handler: () => void parentComponent?.triggerCommand(command)+ });+ /** Drawn as a strip of cards at the top of the menu on a phone. */+ const mobileActions = [+ commandAction("searchNotes", "bx bx-search", t("global_menu.search_notes")),+ commandAction("showRecentChanges", "bx bx-history", t("recent_changes.title")),+ commandAction("showDeletedNotes", "bx bx-trash-alt", t("global_menu.show_deleted_notes"))+ ];return (<Dropdown@@ -49,17 +60,13 @@ export default function GlobalMenu({ isHorizontalLayout }: { isHorizontalLayout:</>}mobileBackdrop>- {isMobile() ? <>- <MenuItem command="searchNotes" icon="bx bx-search" text={t("global_menu.search_notes")} />- <MenuItemColumns>- <MenuItem command="showRecentChanges" icon="bx bx-history" text={t("recent_changes.title")} />- <MenuItem command="showDeletedNotes" icon="bx bx-trash-alt" text={t("global_menu.show_deleted_notes")} />- </MenuItemColumns>- </> : <>+ {isMobile() ? (+ <MenuItemRows items={[ { kind: "actions", items: mobileActions, className: "global-menu-strip tn-menu-actions-cards" } ]} />+ ) : <><MenuItem command="openNewWindow" icon="bx bx-window-open" text={t("global_menu.open_new_window")} /><MenuItem command="showDeletedNotes" icon="bx bx-trash-alt" text={t("global_menu.show_deleted_notes")} />+ <FormDropdownDivider /></>}- <FormDropdownDivider />{isMobile() ? (<MenuItemColumns>diff --git a/apps/client/src/widgets/react/FormList.css b/apps/client/src/widgets/react/FormList.cssindex 45aac0e095..a06c699b7e 100644--- a/apps/client/src/widgets/react/FormList.css+++ b/apps/client/src/widgets/react/FormList.css@@ -46,10 +46,6 @@.form-list-col {flex-grow: 1;}-- .dropdown-item + & {- margin-top: 1em;- }}.dropdown-header.dropdown-header-with-action {