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): proper empty state for similar notes
Elian Doranab2a1edaae2c
diff --git a/apps/client/src/widgets/react/NoItems.css b/apps/client/src/widgets/react/NoItems.cssindex aa5d6f5e33..e606ad74eb 100644--- a/apps/client/src/widgets/react/NoItems.css+++ b/apps/client/src/widgets/react/NoItems.css@@ -20,3 +20,12 @@margin-top: 1em;}}++.no-items.no-items-small {+ padding: 1.25em 0.75em;++ .tn-icon {+ font-size: 2em;+ margin-bottom: 0.5rem;+ }+}diff --git a/apps/client/src/widgets/react/NoItems.tsx b/apps/client/src/widgets/react/NoItems.tsxindex d2be7781f6..46be9df6d9 100644--- a/apps/client/src/widgets/react/NoItems.tsx+++ b/apps/client/src/widgets/react/NoItems.tsx@@ -10,11 +10,17 @@ interface NoItemsProps {text: string;children?: ComponentChildren;className?: string;+ /**+ * How much room the placeholder takes. `small` shrinks the icon and the spacing around it, for+ * the places that only have a few lines to spare — a sidebar card or a ribbon tab — where the+ * full-size one would tower over the content it stands in for.+ */+ size?: "normal" | "small";}-export default function NoItems({ icon, text, children, className }: NoItemsProps) {+export default function NoItems({ icon, text, children, className, size }: NoItemsProps) {return (- <div className={clsx("no-items", className)}>+ <div className={clsx("no-items", size === "small" && "no-items-small", className)}><Icon icon={icon} />{text}{children}diff --git a/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx b/apps/client/src/widgets/ribbon/SimilarNotesTab.tsxindex 809db0e55a..4fa9bf64d7 100644--- a/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx+++ b/apps/client/src/widgets/ribbon/SimilarNotesTab.tsx@@ -6,6 +6,7 @@ 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";@@ -27,23 +28,27 @@ export default function SimilarNotesTab({ note }: Pick<TabContext, "note">) {return (<div className="similar-notes-widget">- <div className="similar-notes-wrapper">- {similarNotes?.length ? (- <div>- {similarNotes.map(({notePath, score}) => (- <NoteLink- notePath={notePath}- noTnLink- style={{- "font-size": (1 - 1 / (1 + score)) + "em"- }}- />- ))}- </div>- ) : (- <>{t("similar_notes.no_similar_notes_found")}</>- )}- </div>+ {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>);}