diff --git a/apps/web/app/(all)/[workspaceSlug]/(projects)/sidebar.tsx b/apps/web/app/(all)/[workspaceSlug]/(projects)/sidebar.tsx index 2fd3218c073..f392746443f 100644 --- a/apps/web/app/(all)/[workspaceSlug]/(projects)/sidebar.tsx +++ b/apps/web/app/(all)/[workspaceSlug]/(projects)/sidebar.tsx @@ -1,36 +1,24 @@ -import { FC, useEffect, useRef } from "react"; +import { FC } from "react"; import isEmpty from "lodash/isEmpty"; import { observer } from "mobx-react"; // plane helpers import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants"; -import { useOutsideClickDetector } from "@plane/hooks"; // components -import { AppSidebarToggleButton } from "@/components/sidebar/sidebar-toggle-button"; -import { SidebarDropdown } from "@/components/workspace/sidebar/dropdown"; +import { SidebarWrapper } from "@/components/sidebar/sidebar-wrapper"; import { SidebarFavoritesMenu } from "@/components/workspace/sidebar/favorites/favorites-menu"; -import { HelpMenu } from "@/components/workspace/sidebar/help-menu"; import { SidebarProjectsList } from "@/components/workspace/sidebar/projects-list"; import { SidebarQuickActions } from "@/components/workspace/sidebar/quick-actions"; import { SidebarMenuItems } from "@/components/workspace/sidebar/sidebar-menu-items"; // hooks -import { useAppTheme } from "@/hooks/store/use-app-theme"; import { useFavorite } from "@/hooks/store/use-favorite"; import { useUserPermissions } from "@/hooks/store/user"; -import { useAppRail } from "@/hooks/use-app-rail"; -import useSize from "@/hooks/use-window-size"; // plane web components -import { WorkspaceEditionBadge } from "@/plane-web/components/workspace/edition-badge"; import { SidebarTeamsList } from "@/plane-web/components/workspace/sidebar/teams-sidebar-list"; export const AppSidebar: FC = observer(() => { // store hooks const { allowPermissions } = useUserPermissions(); - const { toggleSidebar, sidebarCollapsed } = useAppTheme(); - const { shouldRenderAppRail, isEnabled: isAppRailEnabled } = useAppRail(); const { groupedFavorites } = useFavorite(); - const windowSize = useSize(); - // refs - const ref = useRef(null); // derived values const canPerformWorkspaceMemberActions = allowPermissions( @@ -38,55 +26,17 @@ export const AppSidebar: FC = observer(() => { EUserPermissionsLevel.WORKSPACE ); - useOutsideClickDetector(ref, () => { - if (sidebarCollapsed === false) { - if (window.innerWidth < 768) { - toggleSidebar(); - } - } - }); - - useEffect(() => { - if (windowSize[0] < 768 && !sidebarCollapsed) toggleSidebar(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [windowSize]); - const isFavoriteEmpty = isEmpty(groupedFavorites); return ( - <> -
- {/* Workspace switcher and settings */} - {!shouldRenderAppRail && } - - {isAppRailEnabled && ( -
- Projects -
- -
-
- )} - {/* Quick actions */} - -
-
- - {/* Favorites Menu */} - {canPerformWorkspaceMemberActions && !isFavoriteEmpty && } - {/* Teams List */} - - {/* Projects List */} - -
- {/* Help Section */} -
- -
- {!shouldRenderAppRail && } - {!isAppRailEnabled && } -
-
- + }> + + {/* Favorites Menu */} + {canPerformWorkspaceMemberActions && !isFavoriteEmpty && } + {/* Teams List */} + + {/* Projects List */} + + ); }); diff --git a/apps/web/core/components/sidebar/sidebar-wrapper.tsx b/apps/web/core/components/sidebar/sidebar-wrapper.tsx new file mode 100644 index 00000000000..386f590cd78 --- /dev/null +++ b/apps/web/core/components/sidebar/sidebar-wrapper.tsx @@ -0,0 +1,72 @@ +import { FC, useEffect, useRef } from "react"; +import { observer } from "mobx-react"; +// plane helpers +import { useOutsideClickDetector } from "@plane/hooks"; +// components +import { AppSidebarToggleButton } from "@/components/sidebar/sidebar-toggle-button"; +import { SidebarDropdown } from "@/components/workspace/sidebar/dropdown"; +import { HelpMenu } from "@/components/workspace/sidebar/help-menu"; +// hooks +import { useAppTheme } from "@/hooks/store/use-app-theme"; +import { useAppRail } from "@/hooks/use-app-rail"; +import useSize from "@/hooks/use-window-size"; +// plane web components +import { WorkspaceEditionBadge } from "@/plane-web/components/workspace/edition-badge"; + +type TSidebarWrapperProps = { + title: string; + children: React.ReactNode; + quickActions?: React.ReactNode; +}; + +export const SidebarWrapper: FC = observer((props) => { + const { children, title, quickActions } = props; + // store hooks + const { toggleSidebar, sidebarCollapsed } = useAppTheme(); + const { shouldRenderAppRail, isEnabled: isAppRailEnabled } = useAppRail(); + const windowSize = useSize(); + // refs + const ref = useRef(null); + + useOutsideClickDetector(ref, () => { + if (sidebarCollapsed === false && window.innerWidth < 768) { + toggleSidebar(); + } + }); + + useEffect(() => { + if (windowSize[0] < 768 && !sidebarCollapsed) toggleSidebar(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [windowSize]); + + return ( +
+
+ {/* Workspace switcher and settings */} + {!shouldRenderAppRail && } + + {isAppRailEnabled && ( +
+ {title} +
+ +
+
+ )} + {/* Quick actions */} + {quickActions} +
+
+ {children} +
+ {/* Help Section */} +
+ +
+ {!shouldRenderAppRail && } + {!isAppRailEnabled && } +
+
+
+ ); +});