Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): enter a workspace at its top level

Elian Doran092b6f6b469d
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
index 78624ad0c4..438dda6e0d 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
@@ -139,19 +139,19 @@ describe("TitleWithIndicators", () => {
});
describe("WorkspaceCards", () => {
- it("lists the workspaces and hoists the tab into the one tapped", async () => {
+ it("lists the workspaces and enters the one tapped", async () => {
const workspace = buildNote({ title: "Work", "#workspace": "", "#workspaceIconClass": "bx bx-briefcase" });
const searchForNotes = vi.spyOn(search, "searchForNotes").mockResolvedValue([ workspace ]);
- const triggerCommand = vi.fn();
+ const onEnter = vi.fn();
const parent = {
- componentId: "cid", registerHandler: () => {}, removeHandler: () => {}, triggerCommand
+ componentId: "cid", registerHandler: () => {}, removeHandler: () => {}
} as unknown as Component;
let container = document.body;
await act(async () => {
container = renderInto(
<ParentComponent.Provider value={parent}>
- <WorkspaceCards />
+ <WorkspaceCards onEnter={onEnter} />
</ParentComponent.Provider>
);
});
@@ -166,7 +166,7 @@ describe("WorkspaceCards", () => {
expect(cards[0]?.querySelector(".mobile-navigator-workspace-icon.bx-briefcase")).not.toBeNull();
(cards[0] as HTMLElement | undefined)?.click();
- expect(triggerCommand).toHaveBeenCalledWith("hoistNote", { noteId: workspace.noteId });
+ expect(onEnter).toHaveBeenCalledWith(workspace.noteId);
});
});
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
index f212f20e71..5b47f69e92 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
@@ -35,7 +35,7 @@ import {
import Icon from "../react/Icon";
import NoItems from "../react/NoItems";
import { ParentComponent } from "../react/react_utils";
-import { getLastSegment, getSpotlightedNoteId, getTreeStack, leaveHoistedNote, setTabTree } from "./tab_navigation";
+import { enterHoistedNote, getLastSegment, getSpotlightedNoteId, getTreeStack, leaveHoistedNote, setTabTree } from "./tab_navigation";
/**
* A touch-native replacement for the Fancytree-based note tree on mobile. Shows one
@@ -206,6 +206,11 @@ export default function MobileNoteNavigator() {
void hoisted_note.unhoist();
}, [tabId, activeNotePath, effectiveHoistedId]);
+ const enterWorkspace = useCallback((noteId: string) => {
+ if (tabId) enterHoistedNote(tabId, activeNotePath, noteId);
+ void parentComponent?.triggerCommand("hoistNote", { noteId });
+ }, [tabId, activeNotePath, parentComponent]);
+
// Registered once, so a menu or dialog opened over the tree later answers back first.
const isTreeShown = useRef(false);
useTriliumEvent("activeScreenChanged", ({ activeScreen }) => {
@@ -283,7 +288,7 @@ export default function MobileNoteNavigator() {
<div ref={scrollRef} className={clsx("mobile-navigator-scroll", showInitialLoader && "is-pending")}>
<div ref={bodyRef} className="mobile-navigator-body">
- {!isHoisted && currentParentId === "root" && <WorkspaceCards />}
+ {!isHoisted && currentParentId === "root" && <WorkspaceCards onEnter={enterWorkspace} />}
{!isHoisted && currentParentId === "root" && (
<BookmarkList
renderRow={({ note, notePath, parentNoteId }) => (
@@ -521,11 +526,10 @@ export function ForwardToNoteButton({ notePath }: { notePath: string }) {
/**
* The workspace notes, as the empty tab lists them, for the root column of a tab that is not
* hoisted: a heading and a grid of cards, each with the workspace's icon over its title.
- * Tapping one hoists the tab into it.
+ * Tapping one calls `onEnter` with its note ID.
*/
-export function WorkspaceCards() {
+export function WorkspaceCards({ onEnter }: { onEnter: (noteId: string) => void }) {
const [ workspaceNotes, setWorkspaceNotes ] = useState<FNote[]>([]);
- const parentComponent = useContext(ParentComponent);
const refresh = useCallback(() => {
search.searchForNotes("#workspace #!template").then(setWorkspaceNotes);
@@ -547,7 +551,7 @@ export function WorkspaceCards() {
<WorkspaceCard
key={workspaceNote.noteId}
note={workspaceNote}
- onClick={() => parentComponent?.triggerCommand("hoistNote", { noteId: workspaceNote.noteId })}
+ onClick={() => onEnter(workspaceNote.noteId)}
/>
))}
</div>
diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
index e49360e4e1..ac82ad1eb6 100644
--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { buildNotes } from "../../test/easy-froca";
-import { forgetTabs, getSpotlightedNoteId, getTabNavigation, getTreeStack, leaveHoistedNote, setTabScreen, setTabTree } from "./tab_navigation";
+import { enterHoistedNote, forgetTabs, getSpotlightedNoteId, getTabNavigation, getTreeStack, leaveHoistedNote, setTabScreen, setTabTree } from "./tab_navigation";
describe("tab navigation", () => {
buildNotes([
@@ -57,4 +57,10 @@ describe("tab navigation", () => {
leaveHoistedNote("leaving", notePath, "folder");
expect(getTreeStack("leaving", notePath, "root")).toEqual([ "root" ]);
});
+
+ it("enters a hoisted note on its own column, even with a note deep inside it open", () => {
+ const notePath = "root/folder/inner/leaf";
+ enterHoistedNote("entering", notePath, "folder");
+ expect(getTreeStack("entering", notePath, "folder")).toEqual([ "folder" ]);
+ });
});
diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
index b9619911d7..671e21f739 100644
--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
@@ -62,6 +62,16 @@ export function leaveHoistedNote(tabId: string, notePath: string | null | undefi
setTabTree(tabId, { notePath, hoistedNoteId: "root", stack: stack.length ? stack : [ "root" ] });
}
+/**
+ * Leaves the tree of `tabId` on the column of `hoistedNoteId` once the tab hoists it, as entering a
+ * folder does, instead of the column of a note inside it that the tab shows. Runs before the
+ * hoisting; when `notePath` lies outside the hoisted note, the hoisting opens the hoisted note
+ * itself, whose tree starts on that column anyway.
+ */
+export function enterHoistedNote(tabId: string, notePath: string | null | undefined, hoistedNoteId: string) {
+ setTabTree(tabId, { notePath, hoistedNoteId, stack: [ hoistedNoteId ] });
+}
+
/**
* The child of the column at `columnPath` that leads to `notePath`, which a column with
* `#subtreeHidden` still lists, as the desktop tree's spotlight does. A hoisted tree's `columnPath`