import { ResizablePanel, ResizablePanelGroup, } from '@affine/admin/components/ui/resizable'; import { Separator } from '@affine/admin/components/ui/separator'; import { TooltipProvider } from '@affine/admin/components/ui/tooltip'; import { cn } from '@affine/admin/utils'; import { cssVarV2 } from '@toeverything/theme/v2'; import { AlignJustifyIcon } from 'lucide-react'; import type { PropsWithChildren, ReactNode, RefObject } from 'react'; import { useCallback, useRef, useState } from 'react'; import type { ImperativePanelHandle } from 'react-resizable-panels'; import { Button } from '../components/ui/button'; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from '../components/ui/sheet'; import { Logo } from './accounts/components/logo'; import { useMediaQuery } from './common'; import { NavContext } from './nav/context'; import { Nav } from './nav/nav'; import { PanelContext, type ResizablePanelProps, useRightPanel, } from './panel/context'; export function Layout({ children }: PropsWithChildren) { const [rightPanelContent, setRightPanelContent] = useState(null); const [leftPanelContent, setLeftPanelContent] = useState(null); const [leftOpen, setLeftOpen] = useState(false); const [rightOpen, setRightOpen] = useState(false); const rightPanelRef = useRef(null); const leftPanelRef = useRef(null); const [activeTab, setActiveTab] = useState(''); const [activeSubTab, setActiveSubTab] = useState('server'); const [currentModule, setCurrentModule] = useState('server'); const handleLeftExpand = useCallback(() => { if (leftPanelRef.current?.getSize() === 0) { leftPanelRef.current?.resize(30); } setLeftOpen(true); }, [leftPanelRef]); const handleLeftCollapse = useCallback(() => { if (leftPanelRef.current?.getSize() !== 0) { leftPanelRef.current?.resize(0); } setLeftOpen(false); }, [leftPanelRef]); const openLeftPanel = useCallback(() => { handleLeftExpand(); leftPanelRef.current?.expand(); setLeftOpen(true); }, [handleLeftExpand]); const closeLeftPanel = useCallback(() => { handleLeftCollapse(); leftPanelRef.current?.collapse(); setLeftOpen(false); }, [handleLeftCollapse]); const toggleLeftPanel = useCallback( () => leftPanelRef.current?.isCollapsed() ? openLeftPanel() : closeLeftPanel(), [openLeftPanel, closeLeftPanel] ); const handleRightExpand = useCallback(() => { if (rightPanelRef.current?.getSize() === 0) { rightPanelRef.current?.resize(30); } setRightOpen(true); }, [rightPanelRef]); const handleRightCollapse = useCallback(() => { if (rightPanelRef.current?.getSize() !== 0) { rightPanelRef.current?.resize(0); } setRightOpen(false); }, [rightPanelRef]); const openRightPanel = useCallback(() => { handleRightExpand(); rightPanelRef.current?.expand(); setRightOpen(true); }, [handleRightExpand]); const closeRightPanel = useCallback(() => { handleRightCollapse(); rightPanelRef.current?.collapse(); setRightOpen(false); }, [handleRightCollapse]); const toggleRightPanel = useCallback( () => rightPanelRef.current?.isCollapsed() ? openRightPanel() : closeRightPanel(), [closeRightPanel, openRightPanel] ); return (
} onExpand={handleLeftExpand} onCollapse={handleLeftCollapse} /> {children} } onExpand={handleRightExpand} onCollapse={handleRightCollapse} />
); } export const LeftPanel = ({ panelRef, onExpand, onCollapse, }: ResizablePanelProps) => { const isSmallScreen = useMediaQuery('(max-width: 768px)'); const isCollapsed = panelRef.current?.isCollapsed(); if (isSmallScreen) { return ( AFFiNE Admin panel for managing accounts, AI, config, and settings
AFFiNE
); } return (
{!isCollapsed && 'AFFiNE'}
); }; export const RightPanel = ({ panelRef, onExpand, onCollapse, }: ResizablePanelProps) => { const isSmallScreen = useMediaQuery('(max-width: 768px)'); const { panelContent, isOpen } = useRightPanel(); const onOpenChange = useCallback( (open: boolean) => { if (open) { onExpand(); } else { onCollapse(); } }, [onExpand, onCollapse] ); if (isSmallScreen) { return ( Right Panel For displaying additional information {panelContent} ); } return ( {panelContent} ); };