Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): backlinks badge opens the sidebar instead of a popup

Elian Doran3f35831bb1d0
diff --git a/apps/client/src/widgets/layout/StatusBar.css b/apps/client/src/widgets/layout/StatusBar.css
index e1e42c764c..0336b18247 100644
--- a/apps/client/src/widgets/layout/StatusBar.css
+++ b/apps/client/src/widgets/layout/StatusBar.css
@@ -66,13 +66,6 @@
.dropdown-note-info {
padding: 1em !important;
}
-
- .backlinks-widget > .dropdown-menu {
- --menu-padding-size: .9em;
-
- max-height: 60vh;
- overflow-y: scroll;
- }
}
> .attribute-list {
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 83cfd0f0ad..992661e5df 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -17,7 +17,7 @@ import { NOTE_TYPES } from "../../services/note_types";
import server from "../../services/server";
import { openInAppHelpFromUrl } from "../../services/utils";
import { formatDateTime } from "../../utils/formatters";
-import { BacklinksList, useBacklinkCount } from "../FloatingButtonsDefinitions";
+import { useBacklinkCount } from "../FloatingButtonsDefinitions";
import Dropdown, { DropdownProps } from "../react/Dropdown";
import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";
import HelpDropdown from "../react/HelpDropdown";
@@ -161,6 +161,24 @@ function StatusBarButton({ className, icon, text, title, active, ...restProps }:
);
}
+/**
+ * Opens the sidebar's connections tab at one of its widgets, and closes it again on a second press —
+ * what the badges standing for a connection of the note offer instead of a popup copy of the list.
+ *
+ * A pane the user keeps closed is peeked rather than docked: the status bar is no place to reflow the
+ * content from. Buttons wired to this carry `right-pane-peek-source`, which is what keeps their press
+ * from dismissing the very peek it is toggling (see RightPanelContainer's peek dismissal).
+ */
+function useConnectionsToggle(expandWidgetId: string) {
+ return useCallback(() => {
+ void appContext.triggerEvent("selectRightPaneTab", {
+ tabId: "connections",
+ peek: true,
+ expandWidgetId
+ });
+ }, [ expandWidgetId ]);
+}
+
//#region Language Switcher
function LanguageSwitcher({ note }: StatusBarContext) {
const [ modalShown, setModalShown ] = useState(false);
@@ -301,18 +319,19 @@ function SimilarNotesPane({ note, similarNotesShown, setSimilarNotesShown }: Not
//#endregion
//#region Backlinks
+/** What points at the note is listed in the sidebar's connections tab, which the badge is the way to. */
function BacklinksBadge({ note, viewScope }: StatusBarContext) {
const count = useBacklinkCount(note, viewScope?.viewMode === "default");
+ const toggleBacklinks = useConnectionsToggle("backlinks");
+
return (note && count > 0 &&
- <StatusBarDropdown
- className="backlinks-badge backlinks-widget tn-backlinks-widget"
+ <StatusBarButton
+ className="backlinks-badge right-pane-peek-source"
icon="bx bx-link"
text={t("status_bar.backlinks", { count })}
title={t("status_bar.backlinks_title", { count })}
- dropdownContainerClassName="backlinks-items"
- >
- <BacklinksList note={note} />
- </StatusBarDropdown>
+ onClick={toggleBacklinks}
+ />
);
}
//#endregion
@@ -428,30 +447,18 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShown
//#endregion
//#region Note paths
-/**
- * The paths themselves live in the sidebar's connections tab, so the badge is only the way in (and, on
- * a second press, out) rather than a second copy of the list in a popup of its own.
- */
+/** Where the note sits in the tree is listed in the sidebar's connections tab, which the badge is the way to. */
function NotePaths({ note, hoistedNoteId }: StatusBarContext) {
const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
const count = sortedNotePaths?.length ?? 0;
-
- const toggleNotePaths = useCallback(() => {
- void appContext.triggerEvent("selectRightPaneTab", {
- tabId: "connections",
- // A glance at the paths from the status bar shouldn't reflow the content around a pane the
- // user has closed; one they keep docked stays docked.
- peek: true,
- expandWidgetId: "notePaths"
- });
- }, []);
+ const toggleNotePaths = useConnectionsToggle("notePaths");
// Keyboard shortcut.
useTriliumEvent("toggleRibbonTabNotePaths", toggleNotePaths);
return (
<StatusBarButton
- className="note-paths-button"
+ className="note-paths-button right-pane-peek-source"
icon="bx bx-directions"
title={t("status_bar.note_paths_title")}
text={t("status_bar.note_paths", { count })}
diff --git a/apps/client/src/widgets/sidebar/Backlinks.tsx b/apps/client/src/widgets/sidebar/Backlinks.tsx
index 89bf0d1133..574d5decda 100644
--- a/apps/client/src/widgets/sidebar/Backlinks.tsx
+++ b/apps/client/src/widgets/sidebar/Backlinks.tsx
@@ -1,5 +1,6 @@
import { t } from "../../services/i18n";
-// The list itself is shared with the status bar's backlinks badge; only the framing differs here.
+// The list itself is shared with the floating backlinks button and the mobile menu; only the framing
+// differs here. The status bar's badge has no list of its own — it opens this one.
import { BacklinksList } from "../FloatingButtonsDefinitions";
import { useActiveNoteContext } from "../react/hooks";
import RightPanelWidget from "./RightPanelWidget";
diff --git a/apps/client/src/widgets/sidebar/NotePaths.tsx b/apps/client/src/widgets/sidebar/NotePaths.tsx
index 26903eae5c..517dc5a596 100644
--- a/apps/client/src/widgets/sidebar/NotePaths.tsx
+++ b/apps/client/src/widgets/sidebar/NotePaths.tsx
@@ -1,7 +1,7 @@
import { t } from "../../services/i18n";
import { useActiveNoteContext } from "../react/hooks";
-// The paths list is shared with the ribbon's note paths tab and the status bar's badge;
-// only the framing differs here.
+// The paths list is shared with the ribbon's note paths tab; only the framing differs here. The status
+// bar's badge has no list of its own — it opens this one.
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
import RightPanelWidget from "./RightPanelWidget";
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index a6e69a8479..1764d503a7 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -108,10 +108,11 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
// Outside-press / Esc *soft*-dismisses the peek: it hides but stays mounted, so re-peeking is
// instant and preserves widget state. The × button and the docked toggle hard-close (unmount).
- // The status bar's note paths badge peeks the pane itself (see selectRightPaneTab above), so
- // dismissing on its press would only close the pane for the click that follows to reopen it.
+ // A `right-pane-peek-source` control (the status bar's connection badges) peeks the pane itself
+ // (see selectRightPaneTab above), so dismissing on its press would only close the pane for the
+ // click that follows to reopen it.
usePeekDismiss(mode === "peek", dismiss, {
- keepOpenSelector: "#right-pane, .right-pane-peek-button, .status-bar .note-paths-button",
+ keepOpenSelector: "#right-pane, .right-pane-peek-button, .right-pane-peek-source",
focusSelector: ".right-pane-peek-button"
});