From bdc2c9265edd127309e7b80d20e113c64f81823e Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia Date: Tue, 13 Feb 2024 12:02:46 +0530 Subject: [PATCH 1/2] chore: app sidebar state fix --- web/layouts/app-layout/sidebar.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/layouts/app-layout/sidebar.tsx b/web/layouts/app-layout/sidebar.tsx index 0ccbf260659..27f3a2f54f2 100644 --- a/web/layouts/app-layout/sidebar.tsx +++ b/web/layouts/app-layout/sidebar.tsx @@ -12,7 +12,7 @@ import { ProjectSidebarList } from "components/project"; import { useApplication } from "hooks/store"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; -export interface IAppSidebar { } +export interface IAppSidebar {} export const AppSidebar: FC = observer(() => { // store hooks @@ -36,7 +36,6 @@ export const AppSidebar: FC = observer(() => { themStore.toggleSidebar(false); } }; - handleResize(); window.addEventListener("resize", handleResize); return () => { window.removeEventListener("resize", handleResize); From 4f3980f8bf7bf4e1ed18d3c8ef5a7524697d8aff Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia Date: Tue, 13 Feb 2024 12:34:55 +0530 Subject: [PATCH 2/2] chore: app sidebar state fix --- .../sidebar/sidebar-menu-hamburger-toggle.tsx | 2 +- web/layouts/app-layout/sidebar.tsx | 25 ++++--------------- web/store/application/theme.store.ts | 22 ++++++++++++++-- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx b/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx index 30d764ab181..b732d8f9528 100644 --- a/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx +++ b/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx @@ -8,7 +8,7 @@ export const SidebarHamburgerToggle: FC = observer(() => { return (
themStore.toggleSidebar()} + onClick={() => themStore.toggleMobileSidebar()} >
diff --git a/web/layouts/app-layout/sidebar.tsx b/web/layouts/app-layout/sidebar.tsx index 27f3a2f54f2..8477525d4a7 100644 --- a/web/layouts/app-layout/sidebar.tsx +++ b/web/layouts/app-layout/sidebar.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useRef } from "react"; +import { FC, useRef } from "react"; import { observer } from "mobx-react-lite"; // components import { @@ -20,34 +20,19 @@ export const AppSidebar: FC = observer(() => { const ref = useRef(null); useOutsideClickDetector(ref, () => { - if (themStore.sidebarCollapsed === false) { + if (themStore.mobileSidebarCollapsed === false) { if (window.innerWidth < 768) { - themStore.toggleSidebar(); + themStore.toggleMobileSidebar(); } } }); - useEffect(() => { - const handleResize = () => { - if (window.innerWidth <= 768) { - themStore.toggleSidebar(true); - } - if (window.innerWidth > 768) { - themStore.toggleSidebar(false); - } - }; - window.addEventListener("resize", handleResize); - return () => { - window.removeEventListener("resize", handleResize); - }; - }, [themStore]); - return (
void; + toggleMobileSidebar: (collapsed?: boolean) => void; setTheme: (theme: any) => void; toggleProfileSidebar: (collapsed?: boolean) => void; toggleWorkspaceAnalyticsSidebar: (collapsed?: boolean) => void; @@ -20,6 +22,7 @@ export interface IThemeStore { export class ThemeStore implements IThemeStore { // observables + mobileSidebarCollapsed: boolean | undefined = true; sidebarCollapsed: boolean | undefined = undefined; theme: string | null = null; profileSidebarCollapsed: boolean | undefined = undefined; @@ -31,6 +34,7 @@ export class ThemeStore implements IThemeStore { constructor(_rootStore: any | null = null) { makeObservable(this, { // observable + mobileSidebarCollapsed: observable.ref, sidebarCollapsed: observable.ref, theme: observable.ref, profileSidebarCollapsed: observable.ref, @@ -38,6 +42,7 @@ export class ThemeStore implements IThemeStore { issueDetailSidebarCollapsed: observable.ref, // action toggleSidebar: action, + toggleMobileSidebar: action, setTheme: action, toggleProfileSidebar: action, toggleWorkspaceAnalyticsSidebar: action, @@ -61,6 +66,19 @@ export class ThemeStore implements IThemeStore { localStorage.setItem("app_sidebar_collapsed", this.sidebarCollapsed.toString()); }; + /** + * Toggle mobile sidebar collapsed state + * @param collapsed + */ + toggleMobileSidebar = (collapsed?: boolean) => { + if (collapsed === undefined) { + this.mobileSidebarCollapsed = !this.mobileSidebarCollapsed; + } else { + this.mobileSidebarCollapsed = collapsed; + } + localStorage.setItem("mobile_sidebar_collapsed", this.mobileSidebarCollapsed.toString()); + }; + /** * Toggle the profile sidebar collapsed state * @param collapsed @@ -88,13 +106,13 @@ export class ThemeStore implements IThemeStore { }; toggleIssueDetailSidebar = (collapsed?: boolean) => { - if(collapsed === undefined) { + if (collapsed === undefined) { this.issueDetailSidebarCollapsed = !this.issueDetailSidebarCollapsed; } else { this.issueDetailSidebarCollapsed = collapsed; } localStorage.setItem("issue_detail_sidebar_collapsed", this.issueDetailSidebarCollapsed.toString()); - } + }; /** * Sets the user theme and applies it to the platform