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): close the attribute page when the note panel hides
Elian Doran1e38571b5faf
diff --git a/apps/client/src/widgets/react/master_detail.spec.tsx b/apps/client/src/widgets/react/master_detail.spec.tsxindex 40531aba55..70f2e7c879 100644--- a/apps/client/src/widgets/react/master_detail.spec.tsx+++ b/apps/client/src/widgets/react/master_detail.spec.tsx@@ -278,6 +278,16 @@ describe("MasterDetailModal", () => {// Closed, so nothing resets it: the announced page is still what the header names.expect(container.querySelector(".tn-master-detail-title")?.textContent).toBe("Attributes");+ expect(close).not.toHaveBeenCalled();+ });++ it("closes the page on show when the modal hides, as its back button would", () => {+ const close = vi.fn();+ renderModal("Attributes", close);+ expect(close).not.toHaveBeenCalled();++ renderModal("Attributes", close, false);+ expect(close).toHaveBeenCalledTimes(1);});it("wraps each half in the class master_detail.css lays it out with", () => {diff --git a/apps/client/src/widgets/react/master_detail.tsx b/apps/client/src/widgets/react/master_detail.tsxindex d254d9888b..c4166b299d 100644--- a/apps/client/src/widgets/react/master_detail.tsx+++ b/apps/client/src/widgets/react/master_detail.tsx@@ -216,11 +216,18 @@ export function MasterDetailModal({ backTitle, listIcon, listActions, children,switchMobileView(title === null ? "list" : "page");}, [ switchMobileView ]);- // Opens on the list, whatever page a previous show was left on.+ // Opens on the list, whatever page a previous show was left on. Hiding closes the page, so that a+ // modal kept in the DOM (`keepInDom`) leaves no page for the system back gesture to act on.+ const pageRef = useRef(page);+ pageRef.current = page;+ const wasShown = useRef(false);useEffect(() => {if (modalProps.show) {resetMobileView("list");+ } else if (wasShown.current) {+ pageRef.current?.close();}+ wasShown.current = modalProps.show;}, [ modalProps.show, resetMobileView ]);return (