Skip to content

Build your personal knowledge base with Trilium Notes

chore(mobile): reuse the narrow layout check for the sidebar toggle

Elian Dorand311a4b8ec82
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index c6503a2a2b..5b36bcbb52 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -2034,7 +2034,6 @@ pre.code-embed-editor.read-only .cm-activeLine {
background-color: var(--left-pane-background-color) !important;
}
- /* Hidden by the sidebar toggle in the title row, like the left pane on desktop. */
#mobile-rest-container > #mobile-sidebar-wrapper.left-pane-hidden {
display: none !important;
}
diff --git a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx
index 2f6841e4c0..6e25268a3d 100644
--- a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx
@@ -18,7 +18,7 @@ import ToggleSidebarButton from "./toggle_sidebar_button";
/** Renders the button at a phone or tablet width and clicks it. */
function clickAt(width: "phone" | "tablet") {
const matchMedia = vi.spyOn(window, "matchMedia").mockImplementation((query) => ({
- matches: width === "tablet" && query === "(min-width: 992px)",
+ matches: width === "phone" && query === "(max-width: 991px)",
media: query
}) as MediaQueryList);
@@ -31,7 +31,7 @@ function clickAt(width: "phone" | "tablet") {
expect(button).not.toBeNull();
button?.click();
- expect(matchMedia).toHaveBeenCalledWith("(min-width: 992px)");
+ expect(matchMedia).toHaveBeenCalledWith("(max-width: 991px)");
expect(activateSplit).not.toHaveBeenCalled();
}
diff --git a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx
index 347f6d7dfc..fa90613b3e 100644
--- a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx
+++ b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx
@@ -1,12 +1,10 @@
import "./toggle_sidebar_button.css";
import { t } from "../../services/i18n";
+import { isNarrowLayout } from "../../services/utils";
import ActionButton from "../react/ActionButton";
import { useNoteContext } from "../react/hooks";
-/** Matches the "Mobile, tablet mode" breakpoint of `style.css`. */
-const TABLET_MODE_QUERY = "(min-width: 992px)";
-
export default function ToggleSidebarButton() {
const { noteContext, parentComponent } = useNoteContext();
@@ -27,7 +25,7 @@ export default function ToggleSidebarButton() {
// In the tablet mode of the mobile layout (see `style.css`) the sidebar sits next
// to the note instead of sliding over it, so the button hides and shows it like the
// left pane toggle on desktop.
- if (window.matchMedia(TABLET_MODE_QUERY).matches) {
+ if (!isNarrowLayout()) {
parentComponent?.triggerCommand("toggleLeftPane");
return;
}