Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): remove the ribbon's similar notes tab

Elian Doran761034380d92
diff --git a/apps/client/src/widgets/layout/StatusBar.css b/apps/client/src/widgets/layout/StatusBar.css
index 75e3e3aea6..b25ba5d93c 100644
--- a/apps/client/src/widgets/layout/StatusBar.css
+++ b/apps/client/src/widgets/layout/StatusBar.css
@@ -227,3 +227,26 @@
}
}
+.similar-notes-widget > .similar-notes-wrapper {
+ /* The font size of the links with the highest similarity score */
+ font-size: 17px;
+}
+
+.similar-notes-wrapper {
+ max-height: 200px;
+ overflow: auto;
+ padding: 12px;
+}
+
+.similar-notes-wrapper a {
+ display: inline-block;
+ border: 1px dotted var(--main-border-color);
+ border-radius: 20px;
+ background-color: var(--accented-background-color);
+ padding: 0 10px 0 10px;
+ margin: 0 3px 0 3px;
+ max-width: 10em;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ overflow: hidden;
+}
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 9b185e7ab5..6c3e62428e 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -1,6 +1,6 @@
import "./StatusBar.css";
-import { getCodeLanguageIcon, Locale, NOTE_TYPE_ICONS, NoteType } from "@triliumnext/commons";
+import { getCodeLanguageIcon, Locale, NOTE_TYPE_ICONS, NoteType, SimilarNoteResponse } from "@triliumnext/commons";
import clsx from "clsx";
import { type ComponentChildren, createPortal, RefObject } from "preact";
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
@@ -9,6 +9,7 @@ import appContext, { CommandNames } from "../../components/app_context";
import NoteContext from "../../components/note_context";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
+import froca from "../../services/froca";
import { t } from "../../services/i18n";
import { ATTRIBUTE_HELP_PAGE } from "../../services/in_app_help";
import { ViewScope } from "../../services/link";
@@ -27,9 +28,10 @@ import HelpDropdown from "../react/HelpDropdown";
import { useActiveNoteContext, useLegacyImperativeHandlers, useNoteLabel, useNoteLabelInt, useNoteLabelOptionalBool, useNoteProperty, useStaticTooltip, useTriliumEvent, useTriliumEvents, useTriliumOptionBool, useTriliumOptionInt, useAttachments } from "../react/hooks";
import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
+import NoItems from "../react/NoItems";
+import NoteLink from "../react/NoteLink";
import { ParentComponent } from "../react/react_utils";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
-import SimilarNotesTab from "../ribbon/SimilarNotesTab";
import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";
import type { RightPaneTabId } from "../sidebar/RightPaneTabs";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
@@ -322,10 +324,53 @@ function SimilarNotesPane({ note, similarNotesShown, setSimilarNotesShown }: Not
visible={similarNotesShown}
setVisible={setSimilarNotesShown}
>
- <SimilarNotesTab note={note} />
+ <SimilarNotesList note={note} />
</BottomPanel>
);
}
+
+export function SimilarNotesList({ note }: { note: FNote | null | undefined }) {
+ const [ similarNotes, setSimilarNotes ] = useState<SimilarNoteResponse>();
+
+ useEffect(() => {
+ if (note) {
+ server.get<SimilarNoteResponse>(`similar-notes/${note.noteId}`).then(async similarNotes => {
+ if (similarNotes) {
+ const noteIds = similarNotes.flatMap((note) => note.notePath);
+ await froca.getNotes(noteIds, true); // preload all at once
+ }
+ setSimilarNotes(similarNotes);
+ });
+ }
+
+ }, [ note?.noteId ]);
+
+ return (
+ <div className="similar-notes-widget">
+ {similarNotes?.length ? (
+ <div className="similar-notes-wrapper">
+ {similarNotes.map(({notePath, score}) => (
+ <NoteLink
+ key={notePath.join("/")}
+ notePath={notePath}
+ noTnLink
+ style={{
+ "font-size": (1 - 1 / (1 + score)) + "em"
+ }}
+ />
+ ))}
+ </div>
+ ) : similarNotes && (
+ // Outside the list's wrapper, whose font size is that of the most similar link.
+ <NoItems
+ size="small"
+ icon="bx bx-bar-chart"
+ text={t("similar_notes.no_similar_notes_found")}
+ />
+ )}
+ </div>
+ );
+}
//#endregion
//#region Backlinks
diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.css b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.css
index 588e4ef0bf..15a83e14bb 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.css
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.css
@@ -1,7 +1,5 @@
-/* The modal is the frame here, so the list keeps neither the cap nor the padding it is given for the
- ribbon's tab (see SimilarNotesTab.css). Kept to the new layout, as it was when it lived in
- StatusBar.css — the old mobile look is not this change's to alter. */
-body.experimental-feature-new-layout .similar-notes-modal .similar-notes-wrapper {
+/* The modal frames the list, so the list drops its own height cap and padding. */
+.similar-notes-modal .similar-notes-wrapper {
max-height: unset;
padding: 0;
}
diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
index 79abd427a2..3239c0cac5 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
@@ -10,7 +10,7 @@ import server from "../../services/server";
import { useLanguageSwitcher } from "../dialogs/content_languages";
import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";
import { codeLanguageItems, useMimeTypes } from "../layout/NoteTypeSwitcher";
-import { getLocaleName, NoteInfoContent } from "../layout/StatusBar";
+import { getLocaleName, NoteInfoContent, SimilarNotesList } from "../layout/StatusBar";
import ActionButton from "../react/ActionButton";
import type { DropdownHandle } from "../react/Dropdown";
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList";
@@ -19,7 +19,6 @@ import { MenuItemRows } from "../react/Menu";
import Modal from "../react/Modal";
import { NoteContextMenu } from "../ribbon/NoteActions";
import NoteActionsCustom from "../ribbon/NoteActionsCustom";
-import SimilarNotesTab from "../ribbon/SimilarNotesTab";
import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
@@ -223,7 +222,7 @@ function SimilarNotesModal({ note, modalShown, setModalShown }: { note: FNote |
show={modalShown}
onHidden={() => setModalShown(false)}
>
- <SimilarNotesTab note={note} />
+ <SimilarNotesList note={note} />
</Modal>
);
}
diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
index 0b2b7ad73f..4ea9157777 100644
--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts
+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
@@ -8,7 +8,6 @@ import NotePropertiesTab from "./NotePropertiesTab";
import { TabConfiguration } from "./ribbon-interface";
import ScriptTab from "./ScriptTab";
import SearchDefinitionTab from "./SearchDefinitionTab";
-import SimilarNotesTab from "./SimilarNotesTab";
export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
{
@@ -57,13 +56,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
toggleCommand: "toggleRibbonTabImageProperties",
activate: true,
},
- {
- title: t("similar_notes.title"),
- icon: "bx bx-bar-chart",
- show: ({ note }) => note?.type !== "search" && !note?.isLabelTruthy("similarNotesWidgetDisabled"),
- content: SimilarNotesTab,
- toggleCommand: "toggleRibbonTabSimilarNotes"
- },
{
title: t("note_info_widget.title"),
icon: "bx bx-info-circle",
diff --git a/apps/client/src/widgets/ribbon/SimilarNotesTab.css b/apps/client/src/widgets/ribbon/SimilarNotesTab.css
deleted file mode 100644
index 753fa879fd..0000000000
--- a/apps/client/src/widgets/ribbon/SimilarNotesTab.css
+++ /dev/null
@@ -1,22 +0,0 @@
-.similar-notes-widget > .similar-notes-wrapper {
- /* The font size of the links with the highest similarity score */
- font-size: 17px;
-}
-.similar-notes-wrapper {
- max-height: 200px;
- overflow: auto;
- padding: 12px;
-}
-
-.similar-notes-wrapper a {
- display: inline-block;
- border: 1px dotted var(--main-border-color);
- border-radius: 20px;
- background-color: var(--accented-background-color);
- padding: 0 10px 0 10px;
- margin: 0 3px 0 3px;
- max-width: 10em;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
-}
diff --git a/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx b/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx
deleted file mode 100644
index 4fa9bf64d7..0000000000
--- a/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import "./SimilarNotesTab.css";
-
-import { SimilarNoteResponse } from "@triliumnext/commons";
-import { useEffect, useState } from "preact/hooks";
-
-import froca from "../../services/froca";
-import { t } from "../../services/i18n";
-import server from "../../services/server";
-import NoItems from "../react/NoItems";
-import NoteLink from "../react/NoteLink";
-import { TabContext } from "./ribbon-interface";
-
-export default function SimilarNotesTab({ note }: Pick<TabContext, "note">) {
- const [ similarNotes, setSimilarNotes ] = useState<SimilarNoteResponse>();
-
- useEffect(() => {
- if (note) {
- server.get<SimilarNoteResponse>(`similar-notes/${note.noteId}`).then(async similarNotes => {
- if (similarNotes) {
- const noteIds = similarNotes.flatMap((note) => note.notePath);
- await froca.getNotes(noteIds, true); // preload all at once
- }
- setSimilarNotes(similarNotes);
- });
- }
-
- }, [ note?.noteId ]);
-
- return (
- <div className="similar-notes-widget">
- {similarNotes?.length ? (
- <div className="similar-notes-wrapper">
- {similarNotes.map(({notePath, score}) => (
- <NoteLink
- key={notePath.join("/")}
- notePath={notePath}
- noTnLink
- style={{
- "font-size": (1 - 1 / (1 + score)) + "em"
- }}
- />
- ))}
- </div>
- ) : similarNotes && (
- // Outside the list's wrapper, whose font size is that of the most similar link.
- <NoItems
- size="small"
- icon="bx bx-bar-chart"
- text={t("similar_notes.no_similar_notes_found")}
- />
- )}
- </div>
- );
-}