Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): similar notes go back to the status bar's own panel

Elian Doran092c8059552f
diff --git a/apps/client/src/services/in_app_help.ts b/apps/client/src/services/in_app_help.ts
index 3b041a1807..f695632e3d 100644
--- a/apps/client/src/services/in_app_help.ts
+++ b/apps/client/src/services/in_app_help.ts
@@ -89,11 +89,6 @@ export const bySidebarSection = {
// Backlinks, covering both kinds one can come from.
helpPage: "wfGXLmm7x27z",
paragraphs: [ "sidebar_help.backlinks_what", "sidebar_help.backlinks_listing" ]
- },
- similarNotes: {
- // Similar Notes.
- helpPage: "xWtq5NUHOwql",
- paragraphs: [ "sidebar_help.similar_notes_what", "sidebar_help.similar_notes_how" ]
}
} satisfies Record<string, SidebarSectionHelp>;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e02af7cfb5..0223c0078c 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1442,9 +1442,7 @@
"note_paths_what": "A note can sit in more than one place in the note tree at once, and each of those places is listed here as a path.",
"note_paths_cloning": "Adding a place is called cloning: nothing is copied, so an edit made under one path shows under all of them, and removing one path leaves the note under the others.",
"backlinks_what": "The notes pointing at this one, either through a link in their text or through a relation naming it.",
- "backlinks_listing": "A text link is listed with the passage around it, a relation with the name it points by. This side of a link is not editable: it goes away when the note that made it drops the link.",
- "similar_notes_what": "Notes that look related to this one even where nothing links them.",
- "similar_notes_how": "The likeness is worked out from the content of the notes, the attributes and relations they carry, and how close together they were created."
+ "backlinks_listing": "A text link is listed with the passage around it, a relation with the name it points by. This side of a link is not editable: it goes away when the note that made it drops the link."
},
"abstract_search_option": {
"remove_this_search_option": "Remove this search option",
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 82afb9aabf..5263f47cac 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -7,7 +7,7 @@ import { type ComponentChildren, RefObject } from "preact";
import { createPortal } from "preact/compat";
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
-import appContext, { CommandNames } from "../../components/app_context";
+import { CommandNames } from "../../components/app_context";
import NoteContext from "../../components/note_context";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
@@ -32,6 +32,7 @@ import AttributeHelp from "../ribbon/components/AttributeHelp";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
+import SimilarNotesTab from "../ribbon/SimilarNotesTab";
import { useAttachments } from "../type_widgets/Attachment";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
import Breadcrumb from "./Breadcrumb";
@@ -47,19 +48,31 @@ interface StatusBarContext {
export default function StatusBar() {
const { note, noteContext, viewScope, hoistedNoteId, notePath } = useActiveNoteContext();
- // The attributes are the one thing the status bar shows in a panel of its own, being edited rather
- // than read; the lists the other badges stand for are read at a glance, so they come as dropdowns.
- const [ attributesShown, setAttributesShown ] = useState(false);
+ // What the status bar shows in a panel rather than a dropdown is what wants the width of the
+ // window: the attributes, which are edited rather than read, and the similar notes, which are set
+ // as a cloud. One at a time — two of them stacked would take the note's place rather than sit
+ // under it.
+ const [ activePane, setActivePane ] = useState<"attributes" | "similar-notes" | false>(false);
const context: StatusBarContext | undefined | null = note && noteContext && { note, noteContext, viewScope, hoistedNoteId, notePath };
- const attributesContext: AttributesProps | undefined | null = context && { ...context, attributesShown, setAttributesShown };
+ const attributesContext: AttributesProps | undefined | null = context && {
+ ...context,
+ attributesShown: activePane === "attributes",
+ setAttributesShown: (shown) => setActivePane(shown && "attributes")
+ };
+ const noteInfoContext: NoteInfoContext | undefined | null = context && {
+ ...context,
+ similarNotesShown: activePane === "similar-notes",
+ setSimilarNotesShown: (shown) => setActivePane(shown && "similar-notes")
+ };
const isHiddenNote = note?.isHiddenCompletely();
return (
- <div className={clsx("status-bar", {"status-bar-panel-open": attributesShown})}>
+ <div className={clsx("status-bar", {"status-bar-panel-open": !!activePane})}>
{attributesContext && <AttributesPane {...attributesContext} />}
+ {noteInfoContext && <SimilarNotesPane {...noteInfoContext} />}
<div className="status-bar-main-row">
- {context && attributesContext && <>
+ {context && attributesContext && noteInfoContext && <>
<Breadcrumb />
<div className="actions-row">
@@ -70,7 +83,7 @@ export default function StatusBar() {
<AttributesButton {...attributesContext} />
<AttachmentCount {...context} />
<BacklinksBadge {...context} />
- <NoteInfoBadge {...context} />
+ <NoteInfoBadge {...noteInfoContext} />
</div>
</>}
</div>
@@ -153,24 +166,6 @@ 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.
- * The way to the one connection the status bar carries no list of its own for: what a note resembles
- * is computed rather than counted, so no badge stands for it to hang a dropdown off.
- *
- * A pane the user keeps closed is peeked rather than docked: the status bar is no place to reflow the
- * content from.
- */
-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);
@@ -225,20 +220,22 @@ export function getLocaleName(locale: Locale | null | undefined) {
}
//#endregion
-//#region Note info
-export function NoteInfoBadge(context: StatusBarContext) {
+//#region Note info & Similar
+interface NoteInfoContext extends StatusBarContext {
+ similarNotesShown?: boolean;
+ setSimilarNotesShown?: (value: boolean) => void;
+}
+
+export function NoteInfoBadge(context: NoteInfoContext) {
const dropdownRef = useRef<BootstrapDropdown>(null);
const [ dropdownShown, setDropdownShown ] = useState(false);
- const { note } = context;
+ const { note, similarNotesShown, setSimilarNotesShown } = context;
const noteType = useNoteProperty(note, "type");
const enabled = note && noteType;
- // What the note resembles is listed in the sidebar's connections tab, alongside the rest of what
- // ties it to other notes, rather than in a panel of the status bar's own.
- const showSimilarNotes = useConnectionsToggle("similarNotes");
// Keyboard shortcuts.
useTriliumEvent("toggleRibbonTabNoteInfo", () => enabled && dropdownRef.current?.show());
- useTriliumEvent("toggleRibbonTabSimilarNotes", showSimilarNotes);
+ useTriliumEvent("toggleRibbonTabSimilarNotes", () => setSimilarNotesShown?.(!similarNotesShown));
return (enabled &&
<StatusBarDropdown
@@ -250,16 +247,14 @@ export function NoteInfoBadge(context: StatusBarContext) {
onShown={() => setDropdownShown(true)}
onHidden={() => setDropdownShown(false)}
>
- {dropdownShown && <NoteInfoContent {...context} dropdownRef={dropdownRef} noteType={noteType} showSimilarNotes={showSimilarNotes} />}
+ {dropdownShown && <NoteInfoContent {...context} dropdownRef={dropdownRef} noteType={noteType} />}
</StatusBarDropdown>
);
}
-export function NoteInfoContent({ note, noteType, dropdownRef, showSimilarNotes }: Pick<StatusBarContext, "note"> & {
+export function NoteInfoContent({ note, noteType, dropdownRef, setSimilarNotesShown }: Pick<NoteInfoContext, "note" | "setSimilarNotesShown"> & {
dropdownRef?: RefObject<BootstrapDropdown>;
noteType: NoteType;
- /** Left out where there is no sidebar to show them in — the mobile note menu carries its own list. */
- showSimilarNotes?: () => void;
}) {
const { metadata, ...sizeProps } = useNoteMetadata(note);
const [ originalFileName ] = useNoteLabel(note, "originalFileName");
@@ -277,11 +272,11 @@ export function NoteInfoContent({ note, noteType, dropdownRef, showSimilarNotes
<NoteInfoValue text={t("note_info_widget.note_size")} title={t("note_info_widget.note_size_info")} value={<NoteSizeWidget {...sizeProps} />} />
</ul>
- {showSimilarNotes && <LinkButton
+ {setSimilarNotesShown && <LinkButton
text={t("note_info_widget.show_similar_notes")}
onClick={() => {
dropdownRef?.current?.hide();
- showSimilarNotes();
+ setSimilarNotesShown(true);
}}
/>}
</div>
@@ -296,6 +291,18 @@ function NoteInfoValue({ text, title, value }: { text: string; title?: string, v
</li>
);
}
+
+function SimilarNotesPane({ note, similarNotesShown, setSimilarNotesShown }: NoteInfoContext) {
+ return (similarNotesShown &&
+ <BottomPanel title={t("similar_notes.title")}
+ className="similar-notes-pane"
+ visible={similarNotesShown}
+ setVisible={setSimilarNotesShown}
+ >
+ <SimilarNotesTab note={note} />
+ </BottomPanel>
+ );
+}
//#endregion
//#region Backlinks
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index 68d58b8cfa..f01f866bbf 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -31,7 +31,6 @@ import PdfPages from "./pdf/PdfPages";
import RightPanelWidget, { CollapsibleWidgets, ExpandWidgetRequest, ExpandWidgetRequests } from "./RightPanelWidget";
import RightPanePeekButton from "./RightPanePeekButton";
import RightPaneTabs, { RIGHT_PANE_TABS, RightPaneTabDefinition, RightPaneTabId } from "./RightPaneTabs";
-import SimilarNotes from "./SimilarNotes";
import TableOfContents from "./TableOfContents";
const MIN_WIDTH_PERCENT = 5;
@@ -75,7 +74,7 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
useTriliumEvent("toggleRightPane", toggleDocked);
useTriliumEvent("peekRightPane", togglePeek);
- // An entry point aimed at one tab (the chat launcher, the status bar's similar notes link): it opens
+ // An entry point aimed at one tab (the chat launcher, the note map's keyboard action): it opens
// the pane on that tab, brings it to the front if the pane is already open on another one, and puts
// it away again when it is the tab on show — see reduceTabSelection for what that amounts to.
// `peek` opens it as a glance instead of a dock; `expandWidgetId` opens the one widget the entry
@@ -235,11 +234,6 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent):
enabled: !!note,
tab: "connections"
},
- {
- el: <SimilarNotes />,
- enabled: !!note,
- tab: "connections"
- },
{
el: <TableOfContents />,
enabled: (noteType === "text" || noteType === "doc" || isPdf || noteType === "llmChat" || !!note?.isMarkdown()),
diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
index b5a38cf580..c24750f0da 100644
--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
@@ -14,8 +14,8 @@ import { ParentComponent } from "../react/react_utils";
export const CollapsibleWidgets = createContext(true);
/**
- * A request to expand one widget of the pane, raised by an entry point aimed at it (the status bar's
- * similar notes link) so that it doesn't land on a widget the user has collapsed. The counter tells
+ * A request to expand one widget of the pane, raised by an entry point aimed at it (the note map's
+ * keyboard action) so that it doesn't land on a widget the user has collapsed. The counter tells
* repeated requests apart, so the widget opens again after having been collapsed in between.
*/
export interface ExpandWidgetRequest {
diff --git a/apps/client/src/widgets/sidebar/SimilarNotes.css b/apps/client/src/widgets/sidebar/SimilarNotes.css
deleted file mode 100644
index 133581ac66..0000000000
--- a/apps/client/src/widgets/sidebar/SimilarNotes.css
+++ /dev/null
@@ -1,6 +0,0 @@
-/* The card scrolls its own body (see RightPanelContainer.css), so the list is not capped a second time
- within it — the cap in SimilarNotesTab.css is for the ribbon's tab, which has no such frame around it. */
-#right-pane .similar-notes-widget .similar-notes-wrapper {
- max-height: unset;
- padding: 0;
-}
diff --git a/apps/client/src/widgets/sidebar/SimilarNotes.tsx b/apps/client/src/widgets/sidebar/SimilarNotes.tsx
deleted file mode 100644
index e8d7c113ef..0000000000
--- a/apps/client/src/widgets/sidebar/SimilarNotes.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import "./SimilarNotes.css";
-
-import { t } from "../../services/i18n";
-import { useActiveNoteContext } from "../react/hooks";
-// The list itself is shared with the ribbon's similar notes tab and the mobile note menu; only the
-// framing differs here. The status bar has no panel of its own for them — it opens this one.
-import SimilarNotesTab from "../ribbon/SimilarNotesTab";
-import RightPanelWidget from "./RightPanelWidget";
-import SidebarHelp from "./SidebarHelp";
-
-export default function SimilarNotes() {
- const { note } = useActiveNoteContext();
-
- return (
- <RightPanelWidget
- id="similarNotes"
- title={t("similar_notes.title")}
- buttons={<SidebarHelp section="similarNotes" />}
- >
- {note && <SimilarNotesTab note={note} />}
- </RightPanelWidget>
- );
-}
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index 0c82d0fe3b..0c2b563945 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -196,7 +196,7 @@ const defaultOptions: DefaultOption[] = [
{ name: "leftPaneVisible", value: "true", isSynced: false },
{ name: "rightPaneWidth", value: "25", isSynced: false },
{ name: "rightPaneVisible", value: "true", isSynced: false },
- { name: "rightPaneCollapsedItems", value: '["similarNotes"]', isSynced: false },
+ { name: "rightPaneCollapsedItems", value: "[]", isSynced: false },
{ name: "rightPaneSelectedTab", value: "outline", isSynced: false },
// Synced, unlike the rest of the pane's state: which map to read connections as is a preference
// rather than where a window happens to be left standing.