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(client): open the sidebar's help as a popup rather than a split
Elian Doran85520ad773e0
diff --git a/apps/client/src/widgets/react/HelpButton.tsx b/apps/client/src/widgets/react/HelpButton.tsxindex 178bc31c8f..fb5e3c4dc0 100644--- a/apps/client/src/widgets/react/HelpButton.tsx+++ b/apps/client/src/widgets/react/HelpButton.tsx@@ -23,15 +23,27 @@ export default function HelpButton({ className, helpPage, title, style }: HelpBu<buttonclass={`${className ?? ""} icon-action bx bx-help-circle`}type="button"- onClick={() => {- if (isInModal) {- void appContext.triggerCommand("openInPopup", { noteIdOrPath: `_help_${helpPage}` });- } else {- void openInAppHelpFromUrl(helpPage);- }- }}+ onClick={() => openHelpPage(helpPage, isInModal)}title={title ?? t("open-help-page")}style={style}/>);}++/**+ * Opens an in-app help page, either as a quick-edit popup over the app or — by default — in a split+ * beside the note being read.+ *+ * The popup is for hosts a split would be lost behind or would shove aside: a modal such as the+ * options dialog, or the right sidebar, whose cards are a glance rather than a place to settle into.+ *+ * @param inAppHelpPage the ID of the help note (excluding the `_help_` prefix).+ * @param inPopup whether to open it as a quick-edit popup rather than a split.+ */+export function openHelpPage(inAppHelpPage: string, inPopup: boolean) {+ if (inPopup) {+ void appContext.triggerCommand("openInPopup", { noteIdOrPath: `_help_${inAppHelpPage}` });+ } else {+ void openInAppHelpFromUrl(inAppHelpPage);+ }+}diff --git a/apps/client/src/widgets/react/HelpDropdown.tsx b/apps/client/src/widgets/react/HelpDropdown.tsxindex 3e0e453551..bd5b15dad5 100644--- a/apps/client/src/widgets/react/HelpDropdown.tsx+++ b/apps/client/src/widgets/react/HelpDropdown.tsx@@ -3,8 +3,8 @@ import "./HelpDropdown.css";import { ComponentChildren } from "preact";import { t } from "../../services/i18n";-import { openInAppHelpFromUrl } from "../../services/utils";import Dropdown from "./Dropdown";+import { openHelpPage } from "./HelpButton";import LinkButton from "./LinkButton";interface HelpDropdownProps {@@ -12,6 +12,11 @@ interface HelpDropdownProps {children: ComponentChildren;/** In-app help note ID; when set, a link to the full help page is appended below the content. */helpPage?: string;+ /**+ * Open {@link helpPage} as a quick-edit popup over the app instead of in a split beside the note.+ * For hosts the split would be lost behind or would shove aside — see {@link openHelpPage}.+ */+ openInPopup?: boolean;className?: string;/** Called as the popup opens, for hosts that need to dismiss their own popups first. */onShown?: () => void;@@ -25,7 +30,7 @@ interface HelpDropdownProps {* explicitly (click outside or <kbd>Escape</kbd>) instead of on blur, so its content stays readable* and selectable.*/-export default function HelpDropdown({ children, helpPage, className, onShown }: HelpDropdownProps) {+export default function HelpDropdown({ children, helpPage, openInPopup, className, onShown }: HelpDropdownProps) {return (<DropdownonShown={onShown}@@ -47,7 +52,7 @@ export default function HelpDropdown({ children, helpPage, className, onShown }:{helpPage && (<LinkButtontext={t("open-help-page")}- onClick={() => void openInAppHelpFromUrl(helpPage)}+ onClick={() => openHelpPage(helpPage, !!openInPopup)}/>)}</Dropdown>diff --git a/apps/client/src/widgets/sidebar/SidebarHelp.tsx b/apps/client/src/widgets/sidebar/SidebarHelp.tsxindex 50840784f2..36dfbfb084 100644--- a/apps/client/src/widgets/sidebar/SidebarHelp.tsx+++ b/apps/client/src/widgets/sidebar/SidebarHelp.tsx@@ -15,13 +15,15 @@ import HelpDropdown from "../react/HelpDropdown";* A dropdown rather than a plain `HelpButton`: the questions a sidebar card raises are short-answer* ones, and sending the reader of a glance-sized pane off into a help page over the note they were* reading is a long way round for a sentence. The full page is still a press away at the foot of the- * popup.+ * popup — as a quick-edit popup rather than a split, for the same reason the pane is a glance: a+ * split would rearrange the window around a note that is only being looked up, and while the pane is+ * peeked it would open underneath the overlay the reader is reading from.*/export default function SidebarHelp({ section }: { section: SidebarSectionId }) {const { helpPage, paragraphs } = bySidebarSection[section];return (- <HelpDropdown helpPage={helpPage}>+ <HelpDropdown helpPage={helpPage} openInPopup>{/* The popup is portalled to the body, so the styling has to hang off a class within itrather than off the dropdown's own. */}<div class="sidebar-help">