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/tab_switcher): add context menu item for closing all tabs
Elian Dorana72d4f425a63
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex e7f48008ce..6bd13a3346 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2274,6 +2274,7 @@},"mobile_tab_switcher": {"title_one": "{{count}} tab",- "title_other": "{{count}} tabs"+ "title_other": "{{count}} tabs",+ "more_options": "More options"}}diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsxindex c716731821..994fc834d5 100644--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx@@ -4,9 +4,10 @@ import clsx from "clsx";import { createPortal } from "preact/compat";import { useCallback, useEffect, useRef, useState } from "preact/hooks";-import appContext from "../../components/app_context";+import appContext, { CommandNames } from "../../components/app_context";import NoteContext from "../../components/note_context";import FNote from "../../entities/fnote";+import contextMenu from "../../menus/context_menu";import { getHue, parseColor } from "../../services/css_class_manager";import froca from "../../services/froca";import { t } from "../../services/i18n";@@ -55,6 +56,26 @@ function TabBarModal({ mainNoteContexts, shown, setShown }: {title={t("mobile_tab_switcher.title", { count: mainNoteContexts.length})}show={shown}onShown={() => setFullyShown(true)}+ customTitleBarButtons={[+ {+ iconClassName: "bx bx-dots-vertical-rounded",+ title: t("mobile_tab_switcher.more_options"),+ onClick(e) {+ contextMenu.show<CommandNames>({+ x: e.pageX,+ y: e.pageY,+ items: [+ { title: t("tab_row.close_all_tabs"), command: "closeAllTabs", uiIcon: "bx bx-empty" },+ ],+ selectMenuItemHandler: ({ command }) => {+ if (command) {+ appContext.triggerCommand(command);+ }+ }+ });+ },+ }+ ]}footer={<><LinkButtontext={t("tab_row.new_tab")}diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsxindex d444f9339c..917c3bd996 100644--- a/apps/client/src/widgets/react/Modal.tsx+++ b/apps/client/src/widgets/react/Modal.tsx@@ -1,17 +1,18 @@+import { Modal as BootstrapModal } from "bootstrap";import clsx from "clsx";-import { useEffect, useRef, useMemo } from "preact/hooks";-import { t } from "../../services/i18n";import { ComponentChildren } from "preact";import type { CSSProperties, RefObject } from "preact/compat";-import { openDialog } from "../../services/dialog";-import { Modal as BootstrapModal } from "bootstrap";import { memo } from "preact/compat";+import { useEffect, useMemo,useRef } from "preact/hooks";++import { openDialog } from "../../services/dialog";+import { t } from "../../services/i18n";import { useSyncedRef } from "./hooks";interface CustomTitleBarButton {title: string;iconClassName: string;- onClick: () => void;+ onClick: (e: MouseEvent) => void;}export interface ModalProps {@@ -80,7 +81,7 @@ export interface ModalProps {noFocus?: boolean;}-export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden: onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus }: ModalProps) {+export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus }: ModalProps) {const modalRef = useSyncedRef<HTMLDivElement>(externalModalRef);const modalInstanceRef = useRef<BootstrapModal>();const elementToFocus = useRef<Element | null>();@@ -116,7 +117,7 @@ export default function Modal({ children, className, size, title, customTitleBarfocus: !noFocus}).then(($widget) => {modalInstanceRef.current = BootstrapModal.getOrCreateInstance($widget[0]);- })+ });} else {modalInstanceRef.current?.hide();}@@ -159,13 +160,12 @@ export default function Modal({ children, className, size, title, customTitleBar{titleBarButtons?.filter((b) => b !== null).map((titleBarButton) => (<button type="button"- className={clsx("custom-title-bar-button bx", titleBarButton.iconClassName)}- title={titleBarButton.title}- onClick={titleBarButton.onClick}>- </button>+ className={clsx("custom-title-bar-button bx", titleBarButton.iconClassName)}+ title={titleBarButton.title}+ onClick={titleBarButton.onClick} />))}- <button type="button" className="btn-close" data-bs-dismiss="modal" aria-label={t("modal.close")}></button>+ <button type="button" className="btn-close" data-bs-dismiss="modal" aria-label={t("modal.close")} /></div>