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
fix(mobile): switch tabs without sliding between tree and note
Elian Doran784eabd80b33
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 43ba39e3ae..fb87661b29 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -1920,6 +1920,14 @@ pre.code-embed-editor.read-only .cm-activeLine {opacity: 0;}+ #mobile-rest-container.instant-screen-change {+ > #mobile-sidebar-wrapper,+ > #detail-container,+ > #detail-container::before {+ transition: none !important;+ }+ }+body[dir="rtl"] #detail-container::before {background: linear-gradient(to right, rgba(0, 0, 0, 0.12), transparent);}diff --git a/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts b/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.tsindex 060d063261..fd9918b996 100644--- a/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts+++ b/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts@@ -68,9 +68,11 @@ describe("SidebarContainer", () => {removeEventListener: vi.fn()}) as unknown as MediaQueryList);- tree = document.body.appendChild(document.createElement("div"));+ const rest = document.body.appendChild(document.createElement("div"));+ rest.id = "mobile-rest-container";+ tree = rest.appendChild(document.createElement("div"));tree.id = "mobile-sidebar-wrapper";- detail = document.body.appendChild(document.createElement("div"));+ detail = rest.appendChild(document.createElement("div"));detail.id = "detail-container";});@@ -157,6 +159,36 @@ describe("SidebarContainer", () => {expect(getTabNavigation("opened")?.screen).toBe("tree");});+ it("swaps the screen in place on a tab switch, and slides it within a tab", () => {+ const sidebar = render(true);+ vi.spyOn(sidebar, "triggerCommand").mockImplementation(() => undefined);+ const rest = tree.parentElement;+ if (!rest) throw new Error("No container");+ const flushes: { instant: boolean, transform: string }[] = [];+ Object.defineProperty(rest, "offsetWidth", { get: () => {+ flushes.push({ instant: rest.classList.contains("instant-screen-change"), transform: detail.style.transform });+ return 0;+ } });+ const switchTo = (ntxId: string) => sidebar.activeContextChangedEvent({+ noteContext: { getMainContext: () => ({ ntxId }) } as unknown as NoteContext+ });++ switchTo("swap-tree");+ sidebar.activeScreenChangedEvent({ activeScreen: "tree" });+ switchTo("swap-note");+ sidebar.activeScreenChangedEvent({ activeScreen: "detail" });+ flushes.length = 0;++ switchTo("swap-tree");+ expect(flushes).toEqual([ { instant: true, transform: "translateX(100%)" } ]);+ expect(rest.classList.contains("instant-screen-change")).toBe(false);++ flushes.length = 0;+ sidebar.activeScreenChangedEvent({ activeScreen: "detail" });+ expect(flushes).toEqual([]);+ expect(detail.style.transform).toBe("");+ });+it("puts the tree back beside the note once the screen widens to a tablet", () => {const sidebar = render(true);sidebar.activeScreenChangedEvent({ activeScreen: "tree" });diff --git a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts b/apps/client/src/widgets/mobile_widgets/sidebar_container.tsindex 0f7ca99d60..60ab6a633e 100644--- a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts+++ b/apps/client/src/widgets/mobile_widgets/sidebar_container.ts@@ -223,10 +223,25 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {// A tab that never showed the tree shows its note.if (isNarrowLayout()) {- this.triggerCommand("setActiveScreen", { screen: getTabNavigation(tabId)?.screen ?? "detail" });+ const screen = getTabNavigation(tabId)?.screen ?? "detail";+ this.#setInitialState();+ this.#withoutTransition(() => this.#setSidebarOpen(screen === this.screenName));+ this.triggerCommand("setActiveScreen", { screen });}}+ /** Applies `change` at once: the slide between the tree and the note is for moving within a tab. */+ #withoutTransition(change: () => void) {+ const container = this.sidebarEl.parentElement;+ if (!container) return change();++ container.classList.add("instant-screen-change");+ change();+ // Reading the layout applies the change while transitions are off.+ void container.offsetWidth;+ container.classList.remove("instant-screen-change");+ }+noteContextRemovedEvent({ ntxIds }: EventData<"noteContextRemoved">) {forgetTabs(ntxIds);}