import { useBreakpoint } from 'common' import { useEffect } from 'react' import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state' import { cn, ResizableHandle, ResizablePanel } from 'ui' import { useMobileSheet } from '../NavigationBar/MobileSheetContext' // Having these params as props as otherwise it's quite hard to visually check the sizes in DefaultLayout // as react resizeable panels requires all these values to be valid to render correctly interface LayoutSidebarProps { minSize?: string | number maxSize?: string | number defaultSize?: string | number } export const LayoutSidebar = ({ minSize = '30', maxSize = '50', defaultSize = '30', }: LayoutSidebarProps) => { const { activeSidebar } = useSidebarManagerSnapshot() const isMobile = useBreakpoint('md') const { setContent: setMobileSheetContent } = useMobileSheet() // On mobile, sidebar content is shown in the sheet. Sync sheet content with active sidebar; clear when none or when switching to desktop. useEffect(() => { if (!isMobile) { setMobileSheetContent(null) return } if (activeSidebar?.component) { setMobileSheetContent(activeSidebar.id) } else { setMobileSheetContent(null) } }, [isMobile, activeSidebar, setMobileSheetContent]) if (!activeSidebar?.component) return null if (isMobile) return null return ( <> {activeSidebar?.component()} ) }