Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): proper empty state for backlinks

Elian Doran9ee1994d8515
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c3c5d535ba..717d8816e1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1201,7 +1201,8 @@
"zpetne_odkazy": {
"backlink_one": "{{count}} Backlink",
"backlink_other": "{{count}} Backlinks",
- "relation": "relation"
+ "relation": "relation",
+ "no_backlinks": "No notes link to this one."
},
"mobile_detail_menu": {
"insert_child_note": "Insert child note",
diff --git a/apps/client/src/widgets/Backlinks.css b/apps/client/src/widgets/Backlinks.css
index e944dfd289..713d11a787 100644
--- a/apps/client/src/widgets/Backlinks.css
+++ b/apps/client/src/widgets/Backlinks.css
@@ -100,3 +100,17 @@
font-size: .85em;
}
}
+
+/* The placeholder for a note nothing points at stands in the list as an item of it, so that it is
+ held by whichever container the list is given (see BacklinksList in FloatingButtonsDefinitions).
+ The card it stands in within the sidebar takes the height the tab leaves over, and the placeholder
+ is handed that height down the chain — it is the card's whole answer, not the first row of a list
+ that isn't there. */
+#right-pane .tn-backlinks-widget:has(.backlinks-empty),
+#right-pane .tn-backlinks-widget .backlinks-items:has(.backlinks-empty),
+#right-pane .backlinks-empty {
+ display: flex;
+ flex-direction: column;
+ flex-grow: 1;
+ min-height: 0;
+}
diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
index 899c30392d..30ea2dc139 100644
--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
@@ -22,6 +22,7 @@ import { ViewTypeOptions } from "./collections/interface";
import ActionButton, { ActionButtonProps } from "./react/ActionButton";
import { ButtonGroup } from "./react/Button";
import { useEffectiveReadOnly, useIsNoteReadOnly, useNoteLabel, useNoteLabelBoolean, useTriliumEvent, useTriliumOption, useWindowSize } from "./react/hooks";
+import NoItems from "./react/NoItems";
import NoteLink from "./react/NoteLink";
import RawHtml from "./react/RawHtml";
import { isSplitEditorForcedReadOnly, resolveDisplayMode } from "./type_widgets/helpers/split_editor_mode";
@@ -418,7 +419,7 @@ export function useBacklinkCount(note: FNote | null | undefined, isDefaultViewMo
}
export function BacklinksList({ note }: { note: FNote }) {
- const [ backlinks, setBacklinks ] = useState<BacklinksResponse>([]);
+ const [ backlinks, setBacklinks ] = useState<BacklinksResponse>();
function refresh() {
server.get<BacklinksResponse>(`note-map/${note.noteId}/backlinks`).then(async (backlinks) => {
@@ -436,6 +437,20 @@ export function BacklinksList({ note }: { note: FNote }) {
if (needsRefresh(note, loadResults)) refresh();
});
+ // Nothing at all until the request has answered, so that the placeholder below doesn't show for
+ // as long as it takes — the note usually has backlinks, this list being what says it has.
+ if (!backlinks) return null;
+
+ if (!backlinks.length) {
+ return (
+ // An item of the list it stands in for: what holds it is a <ul> everywhere but the
+ // floating button's dropdown, which only opens once there is something to list anyway.
+ <li className="backlinks-empty">
+ <NoItems size="small" icon="bx bx-link" text={t("zpetne_odkazy.no_backlinks")} />
+ </li>
+ );
+ }
+
// Keyed by position: one source note takes a row per relation it points with, so a note ID names
// no single row, and the whole list is rebuilt at once anyway.
return backlinks.map((backlink, index) => (