Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): basic drill-down note navigation

Elian Doranb92f5598f5f3
diff --git a/apps/client/src/layouts/mobile_layout.css b/apps/client/src/layouts/mobile_layout.css
index 396fa4a467..701d261ffd 100644
--- a/apps/client/src/layouts/mobile_layout.css
+++ b/apps/client/src/layouts/mobile_layout.css
@@ -27,50 +27,3 @@ kbd {
max-width: 350px;
}
-/* #region Tree */
-.tree-wrapper {
- max-height: 100%;
- margin-top: 0px;
- overflow-y: auto;
- contain: content;
- padding-inline-start: 10px;
-}
-
-.fancytree-title {
- margin-inline-start: 0.6em !important;
-}
-
-.fancytree-node {
- padding: 5px;
-}
-
-span.fancytree-expander {
- width: 24px !important;
- margin-inline-end: 5px;
-}
-
-.fancytree-loading span.fancytree-expander {
- width: 24px;
- height: 32px;
-}
-
-.fancytree-loading span.fancytree-expander:after {
- width: 20px;
- height: 20px;
- margin-top: 4px;
- border-width: 2px;
- border-style: solid;
-}
-
-.tree-wrapper .collapse-tree-button,
-.tree-wrapper .scroll-to-active-note-button,
-.tree-wrapper .tree-settings-button {
- position: fixed;
- margin-inline-end: 16px;
- display: none;
-}
-
-.tree-wrapper .unhoist-button {
- font-size: 200%;
-}
-/* #endregion */
diff --git a/apps/client/src/layouts/mobile_layout.tsx b/apps/client/src/layouts/mobile_layout.tsx
index edb244b291..5f23c0fbee 100644
--- a/apps/client/src/layouts/mobile_layout.tsx
+++ b/apps/client/src/layouts/mobile_layout.tsx
@@ -15,12 +15,12 @@ import NoteBadges from "../widgets/layout/NoteBadges.jsx";
import NoteTitleActions from "../widgets/layout/NoteTitleActions.jsx";
import StandaloneWarningBar from "../widgets/layout/StandaloneWarningBar";
import MobileDetailMenu from "../widgets/mobile_widgets/mobile_detail_menu.js";
+import MobileNoteNavigator from "../widgets/mobile_widgets/MobileNoteNavigator.jsx";
import ScreenContainer from "../widgets/mobile_widgets/screen_container.js";
import SidebarContainer from "../widgets/mobile_widgets/sidebar_container.js";
import ToggleSidebarButton from "../widgets/mobile_widgets/toggle_sidebar_button.jsx";
import NoteIconWidget from "../widgets/note_icon.jsx";
import NoteTitleWidget from "../widgets/note_title.js";
-import NoteTreeWidget from "../widgets/note_tree.js";
import NoteWrapperWidget from "../widgets/note_wrapper.js";
import NoteDetail from "../widgets/NoteDetail.jsx";
import QuickSearchWidget from "../widgets/quick_search.js";
@@ -48,7 +48,7 @@ export default class MobileLayout {
.css("padding-inline-start", "0")
.css("padding-inline-end", "0")
.css("contain", "content")
- .child(new FlexContainer("column").filling().id("mobile-sidebar-wrapper").child(new QuickSearchWidget()).child(new NoteTreeWidget()))
+ .child(new FlexContainer("column").filling().id("mobile-sidebar-wrapper").child(new QuickSearchWidget()).child(<MobileNoteNavigator />))
)
.child(
new ScreenContainer("detail", "row")
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index dd82d6ee59..bd1050404a 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1861,6 +1861,11 @@
"subtree-hidden-moved-description-collection": "This collection hides its child notes in the tree.",
"subtree-hidden-moved-description-other": "Child notes are hidden in the tree for this note."
},
+ "mobile_note_navigator": {
+ "back": "Go up one level",
+ "loading": "Loading...",
+ "empty": "This note has no children."
+ },
"title_bar_buttons": {
"window-on-top": "Keep Window on Top"
},
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
new file mode 100644
index 0000000000..5a866f51ca
--- /dev/null
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
@@ -0,0 +1,119 @@
+.mobile-note-navigator {
+ display: flex;
+ flex-direction: column;
+ flex: 1 1 auto;
+ min-height: 0;
+ contain: content;
+}
+
+.mobile-navigator-header {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 6px 8px;
+ border-bottom: 1px solid var(--main-border-color);
+ background: var(--main-background-color);
+ position: sticky;
+ top: 0;
+ z-index: 1;
+}
+
+.mobile-navigator-back {
+ flex: 0 0 auto;
+ font-size: 1.6em;
+ min-width: 40px;
+ min-height: 40px;
+}
+
+.mobile-navigator-back.invisible {
+ visibility: hidden;
+}
+
+.mobile-navigator-title {
+ flex: 1 1 auto;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ background: none;
+ border: none;
+ color: var(--main-text-color);
+ padding: 6px 8px;
+ min-height: 40px;
+ font-size: 1.05em;
+ font-weight: 600;
+ text-align: start;
+ min-width: 0;
+ cursor: pointer;
+}
+
+.mobile-navigator-title:disabled {
+ cursor: default;
+ opacity: 0.7;
+}
+
+.mobile-navigator-title-icon {
+ font-size: 1.1em;
+ flex: 0 0 auto;
+}
+
+.mobile-navigator-title-text {
+ flex: 1 1 auto;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.mobile-navigator-list {
+ flex: 1 1 auto;
+ overflow-y: auto;
+ overflow-x: hidden;
+ -webkit-overflow-scrolling: touch;
+ touch-action: pan-y;
+ overscroll-behavior: contain;
+ padding-bottom: env(safe-area-inset-bottom, 0);
+}
+
+.mobile-navigator-row {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ min-height: 48px;
+ padding: 10px 14px;
+ border-bottom: 1px solid var(--main-border-color);
+ color: var(--main-text-color);
+ cursor: pointer;
+ user-select: none;
+ -webkit-tap-highlight-color: transparent;
+}
+
+.mobile-navigator-row:active {
+ background: var(--hover-item-background-color);
+}
+
+.mobile-navigator-row.is-active {
+ background: var(--active-item-background-color);
+ color: var(--active-item-text-color);
+}
+
+.mobile-navigator-row.is-archived {
+ opacity: 0.55;
+}
+
+.mobile-navigator-row-icon {
+ flex: 0 0 auto;
+ font-size: 1.2em;
+}
+
+.mobile-navigator-row-title {
+ flex: 1 1 auto;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-size: 1em;
+}
+
+.mobile-navigator-row-chevron {
+ flex: 0 0 auto;
+ font-size: 1.4em;
+ opacity: 0.6;
+}
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
new file mode 100644
index 0000000000..f76eff90a0
--- /dev/null
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
@@ -0,0 +1,215 @@
+import "./MobileNoteNavigator.css";
+
+import clsx from "clsx";
+import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
+
+import type FNote from "../../entities/fnote";
+import froca from "../../services/froca";
+import { t } from "../../services/i18n";
+import ActionButton from "../react/ActionButton";
+import {
+ useActiveNoteContext,
+ useNote,
+ useNoteIcon,
+ useTriliumEvent,
+ useTriliumOptionBool
+} from "../react/hooks";
+import Icon from "../react/Icon";
+import NoItems from "../react/NoItems";
+
+/**
+ * A touch-native replacement for the Fancytree-based note tree on mobile. Shows one
+ * "column" of children at a time (iOS Files / macOS Finder style), with a back
+ * chevron to pop up the hierarchy and tappable rows to drill in or open notes.
+ */
+export default function MobileNoteNavigator() {
+ const { notePath: activeNotePath, hoistedNoteId, noteContext, parentComponent } = useActiveNoteContext();
+ const [hideArchived] = useTriliumOptionBool("hideArchivedNotes_main");
+
+ const effectiveHoistedId = hoistedNoteId ?? "root";
+ const [stack, setStack] = useState<string[]>([effectiveHoistedId]);
+ const manualStackRef = useRef(false);
+
+ // Sync stack with the active note path unless the user has manually drilled.
+ useEffect(() => {
+ if (manualStackRef.current) return;
+ const newStack = buildStackForActiveNote(activeNotePath, effectiveHoistedId);
+ setStack(newStack);
+ }, [activeNotePath, effectiveHoistedId]);
+
+ // Rebuild when Froca reports structural changes that could affect the current column.
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ const parentPath = stack[stack.length - 1];
+ const parentNoteId = getLastSegment(parentPath);
+ if (loadResults.getBranchRows().some((b) => b.parentNoteId === parentNoteId)) {
+ // No state change, but force a re-render by resetting the same stack reference.
+ setStack((prev) => [...prev]);
+ }
+ });
+
+ const currentParentPath = stack[stack.length - 1];
+ const currentParentId = getLastSegment(currentParentPath);
+ const parentNote = useNote(currentParentId);
+ const activeNoteId = activeNotePath ? getLastSegment(activeNotePath) : undefined;
+
+ const children = useNavigatorChildren(parentNote, hideArchived);
+ const canGoBack = stack.length > 1;
+
+ const goBack = useCallback(() => {
+ manualStackRef.current = true;
+ setStack((prev) => (prev.length > 1 ? prev.slice(0, -1) : prev));
+ }, []);
+
+ const openNote = useCallback(
+ async (childNotePath: string, closeSidebar: boolean) => {
+ await noteContext?.setNote(childNotePath);
+ if (closeSidebar) {
+ manualStackRef.current = false;
+ parentComponent?.triggerCommand("setActiveScreen", { screen: "detail" });
+ }
+ },
+ [noteContext, parentComponent]
+ );
+
+ const drillInto = useCallback(
+ async (childNotePath: string) => {
+ manualStackRef.current = true;
+ setStack((prev) => [...prev, childNotePath]);
+ await noteContext?.setNote(childNotePath);
+ },
+ [noteContext]
+ );
+
+ const openParent = useCallback(() => {
+ if (!currentParentPath) return;
+ openNote(currentParentPath, true);
+ }, [currentParentPath, openNote]);
+
+ return (
+ <div className="mobile-note-navigator">
+ <div className="mobile-navigator-header">
+ <ActionButton
+ className={clsx("mobile-navigator-back", !canGoBack && "invisible")}
+ icon="bx bx-chevron-left"
+ text={t("mobile_note_navigator.back")}
+ onClick={canGoBack ? goBack : undefined}
+ disabled={!canGoBack}
+ />
+ <button
+ type="button"
+ className="mobile-navigator-title"
+ onClick={openParent}
+ disabled={!parentNote}
+ >
+ <Icon icon={parentNote?.getIcon() ?? "bx bx-folder"} className="mobile-navigator-title-icon" />
+ <span className="mobile-navigator-title-text">
+ {parentNote?.title ?? t("mobile_note_navigator.loading")}
+ </span>
+ </button>
+ </div>
+
+ <div className="mobile-navigator-list">
+ {children.length === 0 ? (
+ <NoItems icon="bx bx-folder-open" text={t("mobile_note_navigator.empty")} />
+ ) : (
+ children.map((child) => (
+ <NavigatorRow
+ key={child.branchId}
+ note={child.note}
+ prefix={child.prefix}
+ childNotePath={`${currentParentPath}/${child.note.noteId}`}
+ isActive={child.note.noteId === activeNoteId}
+ onOpen={openNote}
+ onDrill={drillInto}
+ />
+ ))
+ )}
+ </div>
+ </div>
+ );
+}
+
+interface NavigatorRowProps {
+ note: FNote;
+ prefix?: string;
+ childNotePath: string;
+ isActive: boolean;
+ onOpen: (notePath: string, closeSidebar: boolean) => void;
+ onDrill: (notePath: string) => void;
+}
+
+function NavigatorRow({ note, prefix, childNotePath, isActive, onOpen, onDrill }: NavigatorRowProps) {
+ const icon = useNoteIcon(note);
+ const hasChildren = note.hasChildren();
+ const colorClass = note.getColorClass();
+ const title = prefix ? `${prefix} - ${note.title}` : note.title;
+
+ return (
+ <div
+ className={clsx("mobile-navigator-row", colorClass, {
+ "is-active": isActive,
+ "is-archived": note.isArchived,
+ "has-children": hasChildren
+ })}
+ role="button"
+ tabIndex={0}
+ onClick={() => (hasChildren ? onDrill(childNotePath) : onOpen(childNotePath, true))}
+ >
+ <Icon icon={icon ?? "bx bx-note"} className="mobile-navigator-row-icon" />
+ <span className="mobile-navigator-row-title">{title}</span>
+ {hasChildren && <Icon icon="bx bx-chevron-right" className="mobile-navigator-row-chevron" />}
+ </div>
+ );
+}
+
+interface NavigatorChild {
+ note: FNote;
+ branchId: string;
+ prefix?: string;
+}
+
+function useNavigatorChildren(parentNote: FNote | null | undefined, hideArchived: boolean): NavigatorChild[] {
+ return useMemo(() => {
+ if (!parentNote) return [];
+ const result: NavigatorChild[] = [];
+ for (const branch of parentNote.getChildBranches()) {
+ if (!branch) continue;
+ const note = froca.getNoteFromCache(branch.noteId);
+ if (!note) continue;
+ if (note.noteId === "_hidden") continue;
+ if (hideArchived && note.isArchived) continue;
+ result.push({ note, branchId: branch.branchId, prefix: branch.prefix });
+ }
+ return result;
+ }, [parentNote, parentNote?.children?.join(","), hideArchived]);
+}
+
+function getLastSegment(notePath: string): string {
+ const idx = notePath.lastIndexOf("/");
+ return idx >= 0 ? notePath.slice(idx + 1) : notePath;
+}
+
+function buildStackForActiveNote(activeNotePath: string | null | undefined, hoistedId: string): string[] {
+ if (!activeNotePath) return [hoistedId];
+
+ const segments = activeNotePath.split("/");
+ const activeNoteId = segments[segments.length - 1];
+ const activeNote = froca.getNoteFromCache(activeNoteId);
+
+ // If the active note is a folder, show its own children; otherwise show its parent's.
+ const parentSegments = activeNote?.hasChildren() ? segments : segments.slice(0, -1);
+
+ // Clamp to the hoisted root.
+ let start = parentSegments.indexOf(hoistedId);
+ if (start < 0) start = 0;
+ const clamped = parentSegments.slice(start);
+ if (clamped.length === 0) {
+ return [hoistedId];
+ }
+
+ const stack: string[] = [];
+ for (let i = 0; i < clamped.length; i++) {
+ stack.push(clamped.slice(0, i + 1).join("/"));
+ }
+ return stack;
+}