2026-02-24 17:44:43 +08:00
|
|
|
import React, { useRef, useEffect } from 'react';
|
2026-05-24 17:55:01 +07:00
|
|
|
import { animate, motion, useMotionValue } from 'motion/react';
|
2026-01-22 14:12:19 +02:00
|
|
|
import { Header } from './Header';
|
2026-06-09 15:51:04 +03:00
|
|
|
import { Sidebar } from './Sidebar';
|
|
|
|
|
import { SidebarTopBar } from './SidebarTopBar';
|
|
|
|
|
import { TitlebarLeftControls } from './TitlebarLeftControls';
|
2026-07-27 23:07:42 +03:00
|
|
|
import { ProjectContextPanel } from './RightSidebarTabs';
|
2026-02-16 14:15:19 +02:00
|
|
|
import { ContextPanel } from './ContextPanel';
|
2026-07-27 23:07:42 +03:00
|
|
|
import { ContextPanelRail } from './ContextPanelRail';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { ErrorBoundary } from '../ui/ErrorBoundary';
|
|
|
|
|
import { CommandPalette } from '../ui/CommandPalette';
|
|
|
|
|
import { HelpDialog } from '../ui/HelpDialog';
|
2026-02-05 01:59:49 +02:00
|
|
|
import { OpenCodeStatusDialog } from '../ui/OpenCodeStatusDialog';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { SessionSidebar } from '@/components/session/SessionSidebar';
|
|
|
|
|
import { SessionDialogs } from '@/components/session/SessionDialogs';
|
2026-07-28 12:04:39 +03:00
|
|
|
import { ScheduledTasksDialog } from '@/components/session/ScheduledTasksDialog';
|
|
|
|
|
import { ArchiveView } from '@/components/views/ArchiveView';
|
|
|
|
|
import { WorktreesView } from '@/components/views/WorktreesView';
|
2025-12-14 02:29:46 +02:00
|
|
|
import { DiffWorkerProvider } from '@/contexts/DiffWorkerProvider';
|
2026-01-01 14:59:51 +02:00
|
|
|
import { MultiRunLauncher } from '@/components/multirun';
|
2026-07-17 13:17:21 +03:00
|
|
|
import { TerminalView } from '@/components/views/TerminalView';
|
2026-02-24 17:44:43 +08:00
|
|
|
import { DrawerProvider } from '@/contexts/DrawerContext';
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
import { useUIStore } from '@/stores/useUIStore';
|
2026-05-24 17:55:01 +07:00
|
|
|
import { useSessionUIStore } from '@/sync/session-ui-store';
|
2026-06-10 12:00:10 +03:00
|
|
|
import { useUpdatePolling } from '@/hooks/useUpdatePolling';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { useDeviceInfo } from '@/lib/device';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
2026-04-25 16:56:37 +03:00
|
|
|
import { lazyWithChunkRecovery } from '@/lib/chunkLoadRecovery';
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-05-06 02:43:13 +03:00
|
|
|
import { ChatView } from '@/components/views/ChatView';
|
2026-04-23 02:31:42 -07:00
|
|
|
|
2026-07-17 13:17:21 +03:00
|
|
|
// Keep TerminalView eager: the bottom dock reserves its height immediately, so
|
|
|
|
|
// suspending here leaves a large blank panel on slower machines.
|
2026-08-07 09:01:31 +03:00
|
|
|
// Other heavy views stay on-demand to reduce initial bundle parse time:
|
|
|
|
|
// DiffView/FilesView pull the CodeMirror and @pierre/diffs stacks into the
|
|
|
|
|
// startup graph when imported statically.
|
|
|
|
|
const PlanView = lazyWithChunkRecovery(() => import('@/components/views/PlanView').then(m => ({ default: m.PlanView })));
|
|
|
|
|
const GitView = lazyWithChunkRecovery(() => import('@/components/views/GitView').then(m => ({ default: m.GitView })));
|
|
|
|
|
const DiffView = lazyWithChunkRecovery(() => import('@/components/views/DiffView').then(m => ({ default: m.DiffView })));
|
|
|
|
|
const FilesView = lazyWithChunkRecovery(() => import('@/components/views/FilesView').then(m => ({ default: m.FilesView })));
|
2026-06-08 11:50:56 -04:00
|
|
|
const DiagramView = lazyWithChunkRecovery(() => import('@/components/views/DiagramView').then(m => ({ default: m.DiagramView })));
|
2026-04-25 16:56:37 +03:00
|
|
|
const SettingsView = lazyWithChunkRecovery(() => import('@/components/views/SettingsView').then(m => ({ default: m.SettingsView })));
|
|
|
|
|
const SettingsWindow = lazyWithChunkRecovery(() => import('@/components/views/SettingsWindow').then(m => ({ default: m.SettingsWindow })));
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
export const MainLayout: React.FC = () => {
|
2026-04-04 02:19:55 +03:00
|
|
|
const isSidebarOpen = useUIStore((state) => state.isSidebarOpen);
|
2026-08-21 16:57:44 +03:00
|
|
|
const activeSurface = useUIStore((state) => state.activeSurface);
|
2026-04-04 02:19:55 +03:00
|
|
|
const setIsMobile = useUIStore((state) => state.setIsMobile);
|
|
|
|
|
const isSessionSwitcherOpen = useUIStore((state) => state.isSessionSwitcherOpen);
|
|
|
|
|
const isSettingsDialogOpen = useUIStore((state) => state.isSettingsDialogOpen);
|
|
|
|
|
const setSettingsDialogOpen = useUIStore((state) => state.setSettingsDialogOpen);
|
2026-08-07 09:01:31 +03:00
|
|
|
// Mount the windowed settings dialog only after its first open: rendering
|
|
|
|
|
// the lazy component (even closed) makes React fetch the SettingsView
|
|
|
|
|
// chunk graph (CodeMirror editor, vim mode, theme tooling) on startup.
|
|
|
|
|
// Once opened it stays mounted so the close animation and state behave as
|
|
|
|
|
// before.
|
|
|
|
|
const [settingsWindowMounted, setSettingsWindowMounted] = React.useState(false);
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (isSettingsDialogOpen) {
|
|
|
|
|
setSettingsWindowMounted(true);
|
|
|
|
|
}
|
|
|
|
|
}, [isSettingsDialogOpen]);
|
2026-04-04 02:19:55 +03:00
|
|
|
const isMultiRunLauncherOpen = useUIStore((state) => state.isMultiRunLauncherOpen);
|
|
|
|
|
const setMultiRunLauncherOpen = useUIStore((state) => state.setMultiRunLauncherOpen);
|
|
|
|
|
const multiRunLauncherPrefillPrompt = useUIStore((state) => state.multiRunLauncherPrefillPrompt);
|
2026-07-28 12:04:39 +03:00
|
|
|
const isScheduledTasksPageOpen = useUIStore((state) => state.isScheduledTasksDialogOpen);
|
|
|
|
|
const isArchivePageOpen = useUIStore((state) => state.isArchivePageOpen);
|
|
|
|
|
const worktreesPageProjectId = useUIStore((state) => state.worktreesPageProjectId);
|
|
|
|
|
// Any full-page surface replacing the chat area. While open, the chat and
|
|
|
|
|
// secondary views are fully hidden (not just covered) so none of their
|
|
|
|
|
// floating chrome bleeds through, and selecting a session / draft / main
|
|
|
|
|
// tab anywhere closes the surface.
|
|
|
|
|
const isSurfacePageOpen = isScheduledTasksPageOpen || isArchivePageOpen || Boolean(worktreesPageProjectId) || isMultiRunLauncherOpen;
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
const closeSurfacePages = () => useUIStore.getState().closeMainSurfaces();
|
|
|
|
|
const unsubscribeSession = useSessionUIStore.subscribe((state, prev) => {
|
|
|
|
|
const sessionSelected = Boolean(state.currentSessionId) && state.currentSessionId !== prev.currentSessionId;
|
|
|
|
|
// Draft identity change covers re-opening a draft while one is
|
|
|
|
|
// already open (the boolean alone never transitions then).
|
|
|
|
|
const draftOpened = Boolean(state.newSessionDraft?.open) && state.newSessionDraft !== prev.newSessionDraft;
|
|
|
|
|
if (sessionSelected || draftOpened) closeSurfacePages();
|
|
|
|
|
});
|
|
|
|
|
const unsubscribeTab = useUIStore.subscribe((state, prev) => {
|
2026-08-21 16:57:44 +03:00
|
|
|
if (state.activeSurface !== prev.activeSurface) closeSurfacePages();
|
2026-07-28 12:04:39 +03:00
|
|
|
});
|
|
|
|
|
return () => {
|
|
|
|
|
unsubscribeSession();
|
|
|
|
|
unsubscribeTab();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2026-07-27 23:07:42 +03:00
|
|
|
const { isMobile } = useDeviceInfo();
|
2026-05-24 17:55:01 +07:00
|
|
|
const mobilePanelsResetRef = React.useRef(false);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Mobile drawer state
|
2026-02-24 17:44:43 +08:00
|
|
|
const [mobileLeftDrawerOpen, setMobileLeftDrawerOpen] = React.useState(false);
|
2026-05-24 17:55:01 +07:00
|
|
|
const [mobileRightSidebarOpen, setMobileRightSidebarOpen] = React.useState(false);
|
|
|
|
|
const [mobileLeftDrawerVisible, setMobileLeftDrawerVisible] = React.useState(false);
|
|
|
|
|
const [mobileRightDrawerVisible, setMobileRightDrawerVisible] = React.useState(false);
|
|
|
|
|
const setMobileSessionPanelOpen = React.useCallback((open: boolean) => {
|
|
|
|
|
setMobileLeftDrawerOpen(open);
|
|
|
|
|
useUIStore.getState().setSessionSwitcherOpen(open);
|
|
|
|
|
}, []);
|
|
|
|
|
const initialDrawerWidthRef = React.useRef(typeof window === 'undefined' ? 0 : window.innerWidth);
|
2026-02-24 17:44:43 +08:00
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Left drawer motion value
|
2026-05-24 17:55:01 +07:00
|
|
|
const leftDrawerX = useMotionValue(-initialDrawerWidthRef.current);
|
2026-02-24 17:44:43 +08:00
|
|
|
const leftDrawerWidth = useRef(0);
|
|
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Right drawer motion value
|
2026-05-24 17:55:01 +07:00
|
|
|
const rightDrawerX = useMotionValue(initialDrawerWidthRef.current);
|
2026-02-24 17:44:43 +08:00
|
|
|
const rightDrawerWidth = useRef(0);
|
|
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Compute drawer width
|
2026-02-24 17:44:43 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (isMobile) {
|
2026-05-24 17:55:01 +07:00
|
|
|
leftDrawerWidth.current = window.innerWidth;
|
|
|
|
|
rightDrawerWidth.current = window.innerWidth;
|
2026-02-24 17:44:43 +08:00
|
|
|
}
|
|
|
|
|
}, [isMobile]);
|
|
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Sync left drawer state and motion value
|
2026-02-24 17:44:43 +08:00
|
|
|
useEffect(() => {
|
2026-05-24 17:55:01 +07:00
|
|
|
if (!isMobile) {
|
|
|
|
|
setMobileLeftDrawerVisible(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mobileLeftDrawerOpen) {
|
|
|
|
|
setMobileLeftDrawerVisible(true);
|
|
|
|
|
}
|
|
|
|
|
animate(leftDrawerX, mobileLeftDrawerOpen ? 0 : -leftDrawerWidth.current, {
|
|
|
|
|
type: 'spring',
|
2026-02-24 17:44:43 +08:00
|
|
|
stiffness: 400,
|
|
|
|
|
damping: 35,
|
2026-05-24 17:55:01 +07:00
|
|
|
mass: 0.8,
|
2026-02-24 17:44:43 +08:00
|
|
|
});
|
|
|
|
|
}, [mobileLeftDrawerOpen, isMobile, leftDrawerX]);
|
|
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
// Sync right drawer state and motion value
|
2026-02-24 17:44:43 +08:00
|
|
|
useEffect(() => {
|
2026-05-24 17:55:01 +07:00
|
|
|
if (!isMobile) {
|
|
|
|
|
setMobileRightDrawerVisible(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mobileRightSidebarOpen) {
|
|
|
|
|
setMobileRightDrawerVisible(true);
|
|
|
|
|
}
|
|
|
|
|
animate(rightDrawerX, mobileRightSidebarOpen ? 0 : rightDrawerWidth.current, {
|
|
|
|
|
type: 'spring',
|
2026-02-24 17:44:43 +08:00
|
|
|
stiffness: 400,
|
|
|
|
|
damping: 35,
|
2026-05-24 17:55:01 +07:00
|
|
|
mass: 0.8,
|
2026-02-24 17:44:43 +08:00
|
|
|
});
|
2026-05-24 17:55:01 +07:00
|
|
|
}, [isMobile, mobileRightSidebarOpen, rightDrawerX]);
|
2026-02-24 17:44:43 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-05-24 17:55:01 +07:00
|
|
|
if (!isMobile) return;
|
|
|
|
|
return leftDrawerX.on('change', (value) => {
|
|
|
|
|
const width = leftDrawerWidth.current || initialDrawerWidthRef.current;
|
|
|
|
|
const visible = mobileLeftDrawerOpen || value > -width + 0.5;
|
|
|
|
|
setMobileLeftDrawerVisible((previous) => previous === visible ? previous : visible);
|
|
|
|
|
});
|
|
|
|
|
}, [isMobile, leftDrawerX, mobileLeftDrawerOpen]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isMobile) return;
|
|
|
|
|
return rightDrawerX.on('change', (value) => {
|
|
|
|
|
const width = rightDrawerWidth.current || initialDrawerWidthRef.current;
|
|
|
|
|
const visible = mobileRightSidebarOpen || value < width - 0.5;
|
|
|
|
|
setMobileRightDrawerVisible((previous) => previous === visible ? previous : visible);
|
|
|
|
|
});
|
|
|
|
|
}, [isMobile, mobileRightSidebarOpen, rightDrawerX]);
|
|
|
|
|
|
|
|
|
|
// Sync session switcher close events to left drawer.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isMobile && !isSessionSwitcherOpen && mobileLeftDrawerOpen) {
|
|
|
|
|
setMobileSessionPanelOpen(false);
|
2026-02-24 17:44:43 +08:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
}, [isSessionSwitcherOpen, isMobile, mobileLeftDrawerOpen, setMobileSessionPanelOpen]);
|
2026-02-24 17:44:43 +08:00
|
|
|
|
2026-04-01 20:32:32 +08:00
|
|
|
useEffect(() => {
|
2026-05-24 17:55:01 +07:00
|
|
|
if (!isMobile) {
|
|
|
|
|
mobilePanelsResetRef.current = false;
|
2026-04-01 20:32:32 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 17:55:01 +07:00
|
|
|
if (mobilePanelsResetRef.current) {
|
|
|
|
|
return;
|
2026-04-01 20:32:32 +08:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
|
|
|
|
|
mobilePanelsResetRef.current = true;
|
|
|
|
|
setMobileSessionPanelOpen(false);
|
|
|
|
|
setMobileRightSidebarOpen(false);
|
2026-07-27 23:07:42 +03:00
|
|
|
}, [isMobile, setMobileSessionPanelOpen]);
|
2026-04-01 20:32:32 +08:00
|
|
|
|
2026-02-24 17:44:43 +08:00
|
|
|
useEffect(() => {
|
2026-08-21 16:57:44 +03:00
|
|
|
if (!isMobile || activeSurface !== 'chat' || mobileLeftDrawerOpen || mobileRightSidebarOpen || isSettingsDialogOpen) {
|
2026-05-24 17:55:01 +07:00
|
|
|
return;
|
2026-02-24 17:44:43 +08:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
|
|
|
|
|
let disposed = false;
|
|
|
|
|
let timeoutId: number | undefined;
|
|
|
|
|
|
|
|
|
|
const scheduleDraftOpen = (delayMs: number) => {
|
|
|
|
|
timeoutId = window.setTimeout(() => {
|
|
|
|
|
if (disposed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sessionState = useSessionUIStore.getState();
|
|
|
|
|
const uiState = useUIStore.getState();
|
|
|
|
|
if (uiState.activeMainTab !== 'chat' || uiState.isSettingsDialogOpen || sessionState.currentSessionId || sessionState.newSessionDraft?.open) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sessionState.isLoading) {
|
|
|
|
|
scheduleDraftOpen(250);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-01 21:16:36 +03:00
|
|
|
sessionState.openNewSessionDraft({ automatic: true });
|
2026-05-24 17:55:01 +07:00
|
|
|
}, delayMs);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
scheduleDraftOpen(500);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
disposed = true;
|
|
|
|
|
if (timeoutId !== undefined) {
|
|
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-08-21 16:57:44 +03:00
|
|
|
}, [activeSurface, isMobile, isSettingsDialogOpen, mobileLeftDrawerOpen, mobileRightSidebarOpen]);
|
2026-05-24 17:55:01 +07:00
|
|
|
|
|
|
|
|
// Ensure mobile drawers are closed when opening full-screen settings
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isMobile || !isSettingsDialogOpen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMobileSessionPanelOpen(false);
|
|
|
|
|
setMobileRightSidebarOpen(false);
|
2026-07-27 23:07:42 +03:00
|
|
|
}, [isMobile, isSettingsDialogOpen, setMobileSessionPanelOpen]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-06-10 12:00:10 +03:00
|
|
|
useUpdatePolling();
|
2025-12-20 01:04:32 +02:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
const previous = useUIStore.getState().isMobile;
|
|
|
|
|
if (previous !== isMobile) {
|
|
|
|
|
setIsMobile(isMobile);
|
|
|
|
|
}
|
|
|
|
|
}, [isMobile, setIsMobile]);
|
|
|
|
|
|
2026-05-24 01:48:56 +07:00
|
|
|
const handleToggleMobileRightDrawer = React.useCallback(() => {
|
|
|
|
|
if (mobileLeftDrawerOpen) {
|
2026-05-24 17:55:01 +07:00
|
|
|
setMobileSessionPanelOpen(false);
|
2026-05-24 01:48:56 +07:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
setMobileRightSidebarOpen(!mobileRightSidebarOpen);
|
|
|
|
|
}, [mobileLeftDrawerOpen, mobileRightSidebarOpen, setMobileSessionPanelOpen]);
|
2026-05-24 01:48:56 +07:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
const secondaryView = React.useMemo(() => {
|
2026-07-27 23:07:42 +03:00
|
|
|
// Desktop surfaces live in the context panel; the only full-view
|
|
|
|
|
// overlays left there are the terminal (promoted by project actions)
|
|
|
|
|
// and the diagram viewer. Mobile keeps the full tab set.
|
2026-08-21 16:57:44 +03:00
|
|
|
if (!isMobile && activeSurface !== 'terminal' && activeSurface !== 'diagram') {
|
2026-07-27 23:07:42 +03:00
|
|
|
return null;
|
|
|
|
|
}
|
2026-08-21 16:57:44 +03:00
|
|
|
switch (activeSurface) {
|
2026-01-25 15:52:02 +02:00
|
|
|
case 'plan':
|
2026-04-23 02:31:42 -07:00
|
|
|
return <React.Suspense fallback={null}><PlanView /></React.Suspense>;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'git':
|
2026-06-16 21:52:05 +11:00
|
|
|
return <React.Suspense fallback={null}><GitView isActive={!mobileRightSidebarOpen} /></React.Suspense>;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'diff':
|
2026-04-23 02:31:42 -07:00
|
|
|
return <React.Suspense fallback={null}><DiffView /></React.Suspense>;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'terminal':
|
2026-07-17 13:17:21 +03:00
|
|
|
return <TerminalView />;
|
2026-01-15 20:19:06 +02:00
|
|
|
case 'files':
|
2026-04-23 02:31:42 -07:00
|
|
|
return <React.Suspense fallback={null}><FilesView /></React.Suspense>;
|
2026-05-24 01:48:56 +07:00
|
|
|
case 'context':
|
|
|
|
|
return <React.Suspense fallback={null}><ProjectContextPanel /></React.Suspense>;
|
2026-06-08 11:50:56 -04:00
|
|
|
case 'diagram':
|
|
|
|
|
return <React.Suspense fallback={null}><DiagramView /></React.Suspense>;
|
2025-12-07 19:32:53 +02:00
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-08-21 16:57:44 +03:00
|
|
|
}, [activeSurface, isMobile, mobileRightSidebarOpen]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-08-21 16:57:44 +03:00
|
|
|
const isChatActive = activeSurface === 'chat';
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
return (
|
2025-12-14 02:29:46 +02:00
|
|
|
<DiffWorkerProvider>
|
|
|
|
|
<div
|
2026-04-27 16:14:09 +07:00
|
|
|
data-page-scroll-lock="true"
|
2025-12-14 02:29:46 +02:00
|
|
|
className={cn(
|
2026-05-18 23:05:13 +08:00
|
|
|
'main-content-safe-area',
|
2026-06-09 15:51:04 +03:00
|
|
|
isMobile ? 'flex h-[100dvh] flex-col' : 'relative flex h-[100dvh]',
|
2026-04-07 21:46:38 +03:00
|
|
|
'bg-background'
|
2025-12-14 02:29:46 +02:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<CommandPalette />
|
|
|
|
|
<HelpDialog />
|
2026-02-05 01:59:49 +02:00
|
|
|
<OpenCodeStatusDialog />
|
2025-12-14 02:29:46 +02:00
|
|
|
<SessionDialogs />
|
|
|
|
|
|
|
|
|
|
{isMobile ? (
|
2026-02-24 17:44:43 +08:00
|
|
|
<DrawerProvider value={{
|
|
|
|
|
leftDrawerOpen: mobileLeftDrawerOpen,
|
2026-05-24 17:55:01 +07:00
|
|
|
rightDrawerOpen: mobileRightSidebarOpen,
|
2026-02-24 17:44:43 +08:00
|
|
|
toggleLeftDrawer: () => {
|
2026-05-24 17:55:01 +07:00
|
|
|
const nextOpen = !mobileLeftDrawerOpen;
|
|
|
|
|
if (mobileRightSidebarOpen) {
|
|
|
|
|
setMobileRightSidebarOpen(false);
|
2026-02-24 17:44:43 +08:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
setMobileSessionPanelOpen(nextOpen);
|
2026-02-24 17:44:43 +08:00
|
|
|
},
|
2026-05-24 01:48:56 +07:00
|
|
|
toggleRightDrawer: handleToggleMobileRightDrawer,
|
2026-02-24 17:44:43 +08:00
|
|
|
leftDrawerX,
|
|
|
|
|
rightDrawerX,
|
|
|
|
|
leftDrawerWidth,
|
|
|
|
|
rightDrawerWidth,
|
2026-05-24 17:55:01 +07:00
|
|
|
setMobileLeftDrawerOpen: setMobileSessionPanelOpen,
|
|
|
|
|
setRightSidebarOpen: setMobileRightSidebarOpen,
|
2026-02-24 17:44:43 +08:00
|
|
|
}}>
|
2026-02-24 23:38:12 +08:00
|
|
|
{/* Mobile: header + drawer mode */}
|
2026-03-22 22:31:29 +02:00
|
|
|
{!isSettingsDialogOpen && <Header
|
2026-02-24 17:44:43 +08:00
|
|
|
onToggleLeftDrawer={() => {
|
2026-05-24 17:55:01 +07:00
|
|
|
const nextOpen = !mobileLeftDrawerOpen;
|
|
|
|
|
if (mobileRightSidebarOpen) {
|
|
|
|
|
setMobileRightSidebarOpen(false);
|
2026-02-24 17:44:43 +08:00
|
|
|
}
|
2026-05-24 17:55:01 +07:00
|
|
|
setMobileSessionPanelOpen(nextOpen);
|
2026-02-24 17:44:43 +08:00
|
|
|
}}
|
|
|
|
|
onToggleRightDrawer={() => {
|
2026-05-24 01:48:56 +07:00
|
|
|
handleToggleMobileRightDrawer();
|
2026-02-24 17:44:43 +08:00
|
|
|
}}
|
|
|
|
|
leftDrawerOpen={mobileLeftDrawerOpen}
|
2026-05-24 17:55:01 +07:00
|
|
|
rightDrawerOpen={mobileRightSidebarOpen}
|
2026-02-24 17:44:43 +08:00
|
|
|
/>}
|
|
|
|
|
|
2026-02-24 23:38:12 +08:00
|
|
|
{/* Main content area (fixed) */}
|
|
|
|
|
<div
|
2026-04-27 16:14:09 +07:00
|
|
|
data-page-scroll-lock="true"
|
2026-02-24 17:44:43 +08:00
|
|
|
className={cn(
|
|
|
|
|
'flex flex-1 overflow-hidden relative',
|
2026-03-22 22:31:29 +02:00
|
|
|
isSettingsDialogOpen && 'hidden'
|
2025-12-28 02:17:09 +02:00
|
|
|
)}
|
2025-12-18 11:20:37 +02:00
|
|
|
>
|
2026-04-27 16:14:09 +07:00
|
|
|
<main className="w-full h-full overflow-hidden bg-background relative" data-page-scroll-lock="true">
|
2026-07-28 12:04:39 +03:00
|
|
|
<div className={cn('absolute inset-0', (!isChatActive || isSurfacePageOpen) && 'invisible')}>
|
|
|
|
|
<ErrorBoundary><ChatView active={isChatActive && !isSettingsDialogOpen && !isSurfacePageOpen} /></ErrorBoundary>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
2026-02-11 10:08:15 -08:00
|
|
|
{secondaryView && (
|
2026-07-28 12:04:39 +03:00
|
|
|
<div className={cn('absolute inset-0', isSurfacePageOpen && 'invisible')}>
|
2026-02-11 10:08:15 -08:00
|
|
|
<ErrorBoundary>{secondaryView}</ErrorBoundary>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
2026-02-11 10:08:15 -08:00
|
|
|
)}
|
2026-03-22 22:31:29 +02:00
|
|
|
{isMultiRunLauncherOpen && (
|
|
|
|
|
<div className="absolute inset-0 z-10 bg-background">
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
<MultiRunLauncher
|
|
|
|
|
initialPrompt={multiRunLauncherPrefillPrompt}
|
|
|
|
|
onCreated={() => setMultiRunLauncherOpen(false)}
|
|
|
|
|
onCancel={() => setMultiRunLauncherOpen(false)}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-07-28 12:04:39 +03:00
|
|
|
<ErrorBoundary><ScheduledTasksDialog /></ErrorBoundary>
|
|
|
|
|
<ErrorBoundary><ArchiveView /></ErrorBoundary>
|
|
|
|
|
<ErrorBoundary><WorktreesView /></ErrorBoundary>
|
2026-07-11 19:56:29 -04:00
|
|
|
{/* Always mount SessionSidebar on mobile to match desktop behavior.
|
|
|
|
|
Conditional mount (mobileLeftDrawerVisible && ...) caused a
|
|
|
|
|
data-loading cascade on every drawer open: paginated sessions
|
|
|
|
|
fetch, worktree discovery, repo status, PR status, and 10+ memo
|
|
|
|
|
recomputations. On Android PWA this manifested as a >10s delay
|
|
|
|
|
before the drawer became interactive (issue #1695). Visibility is
|
|
|
|
|
controlled by the leftDrawerX transform (off-screen when closed).
|
|
|
|
|
The invisible class matters when fully hidden: leftDrawerWidth is
|
|
|
|
|
not recomputed on resize/rotation, so a closed drawer translated by
|
|
|
|
|
the old width could otherwise peek into the viewport; it also keeps
|
|
|
|
|
the off-screen sidebar out of the tab order and skips painting it. */}
|
|
|
|
|
<motion.div
|
|
|
|
|
className={cn(
|
|
|
|
|
'absolute inset-0 z-20 bg-sidebar',
|
|
|
|
|
!mobileLeftDrawerVisible && 'pointer-events-none invisible',
|
|
|
|
|
)}
|
|
|
|
|
data-page-scroll-lock="true"
|
|
|
|
|
style={{ x: leftDrawerX }}
|
|
|
|
|
aria-hidden={!mobileLeftDrawerOpen}
|
|
|
|
|
>
|
|
|
|
|
<ErrorBoundary>
|
2026-07-21 20:52:20 +03:00
|
|
|
<SessionSidebar mobileVariant isVisible={mobileLeftDrawerVisible} />
|
2026-07-11 19:56:29 -04:00
|
|
|
</ErrorBoundary>
|
|
|
|
|
</motion.div>
|
2026-05-24 17:55:01 +07:00
|
|
|
{mobileRightDrawerVisible && (
|
|
|
|
|
<motion.div className="absolute inset-0 z-20 bg-sidebar" data-page-scroll-lock="true" style={{ x: rightDrawerX }} aria-hidden={!mobileRightSidebarOpen}>
|
|
|
|
|
<ErrorBoundary>
|
2026-06-16 21:52:05 +11:00
|
|
|
<React.Suspense fallback={null}><GitView isActive={mobileRightSidebarOpen} /></React.Suspense>
|
2026-05-24 17:55:01 +07:00
|
|
|
</ErrorBoundary>
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
2026-02-11 10:08:15 -08:00
|
|
|
</main>
|
2026-02-24 23:38:12 +08:00
|
|
|
</div>
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2025-12-28 02:17:09 +02:00
|
|
|
{/* Mobile settings: full screen */}
|
|
|
|
|
{isSettingsDialogOpen && (
|
2026-03-20 01:01:03 +02:00
|
|
|
<div
|
|
|
|
|
className="absolute inset-0 z-10 bg-background"
|
|
|
|
|
style={{ paddingTop: 'var(--oc-safe-area-top, 0px)' }}
|
|
|
|
|
>
|
2026-04-23 02:31:42 -07:00
|
|
|
<ErrorBoundary>
|
|
|
|
|
<React.Suspense fallback={null}>
|
|
|
|
|
<SettingsView onClose={() => setSettingsDialogOpen(false)} />
|
|
|
|
|
</React.Suspense>
|
|
|
|
|
</ErrorBoundary>
|
2025-12-28 02:17:09 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-24 17:44:43 +08:00
|
|
|
</DrawerProvider>
|
2025-12-07 19:32:53 +02:00
|
|
|
) : (
|
|
|
|
|
<>
|
2026-06-09 15:51:04 +03:00
|
|
|
{/* Persistent top-left controls (toggle + project actions) that
|
|
|
|
|
stay put while the sidebar/header animate beneath them. */}
|
|
|
|
|
<TitlebarLeftControls />
|
|
|
|
|
{/* Desktop: full-height Sidebar beside [Header above (chat | RightSidebar)] */}
|
|
|
|
|
<div className="flex flex-1 overflow-hidden" data-page-scroll-lock="true">
|
|
|
|
|
<Sidebar
|
|
|
|
|
isOpen={isSidebarOpen}
|
|
|
|
|
isMobile={isMobile}
|
2026-07-30 16:36:20 +03:00
|
|
|
className="border-border"
|
2026-06-09 15:51:04 +03:00
|
|
|
topBar={<SidebarTopBar />}
|
|
|
|
|
>
|
2026-07-21 20:52:20 +03:00
|
|
|
<SessionSidebar isVisible={isSidebarOpen} />
|
2026-06-09 15:51:04 +03:00
|
|
|
</Sidebar>
|
|
|
|
|
<div className="relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background" data-page-scroll-lock="true">
|
|
|
|
|
<Header />
|
|
|
|
|
<div className="relative flex flex-1 min-h-0 overflow-hidden bg-background" data-page-scroll-lock="true">
|
2026-07-30 16:36:20 +03:00
|
|
|
<div className="relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background" data-page-scroll-lock="true">
|
2026-06-09 15:51:04 +03:00
|
|
|
<div className="flex flex-1 min-h-0 overflow-hidden" data-page-scroll-lock="true">
|
2026-08-09 19:30:25 +03:00
|
|
|
{/* Holds the chat and the context panel together, so its
|
|
|
|
|
width does not move when the context panel opens. The
|
|
|
|
|
work-status panel measures this rather than the chat,
|
|
|
|
|
which the context panel animates. */}
|
|
|
|
|
<div className="relative flex flex-1 min-h-0 min-w-0 overflow-hidden" data-page-scroll-lock="true" data-chat-area="true">
|
2026-06-09 15:51:04 +03:00
|
|
|
<main className="flex-1 overflow-hidden bg-background relative" data-page-scroll-lock="true">
|
2026-07-28 12:04:39 +03:00
|
|
|
<div className={cn('absolute inset-0', (!isChatActive || isSurfacePageOpen) && 'invisible')}>
|
|
|
|
|
<ErrorBoundary><ChatView active={isChatActive && !isSettingsDialogOpen && !isSurfacePageOpen} /></ErrorBoundary>
|
2026-02-09 03:13:34 +02:00
|
|
|
</div>
|
2026-06-09 15:51:04 +03:00
|
|
|
{secondaryView && (
|
2026-07-28 12:04:39 +03:00
|
|
|
<div className={cn('absolute inset-0', isSurfacePageOpen && 'invisible')}>
|
2026-06-09 15:51:04 +03:00
|
|
|
<ErrorBoundary>{secondaryView}</ErrorBoundary>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-07-28 12:04:39 +03:00
|
|
|
{isMultiRunLauncherOpen && (
|
|
|
|
|
<div className="absolute inset-0 z-10 bg-background">
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
{/* isWindowed: the app Header already shows the surface
|
|
|
|
|
title, so skip the launcher's own title bar. */}
|
|
|
|
|
<MultiRunLauncher
|
|
|
|
|
isWindowed
|
|
|
|
|
initialPrompt={multiRunLauncherPrefillPrompt}
|
|
|
|
|
onCreated={() => setMultiRunLauncherOpen(false)}
|
|
|
|
|
onCancel={() => setMultiRunLauncherOpen(false)}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<ErrorBoundary><ScheduledTasksDialog /></ErrorBoundary>
|
|
|
|
|
<ErrorBoundary><ArchiveView /></ErrorBoundary>
|
|
|
|
|
<ErrorBoundary><WorktreesView /></ErrorBoundary>
|
2026-06-09 15:51:04 +03:00
|
|
|
</main>
|
|
|
|
|
<ContextPanel />
|
|
|
|
|
</div>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
2026-02-25 14:32:23 +02:00
|
|
|
</div>
|
2026-07-30 16:36:20 +03:00
|
|
|
<div className="border-t border-border" data-page-scroll-lock="true">
|
2026-07-27 23:07:42 +03:00
|
|
|
<ErrorBoundary><ContextPanelRail /></ErrorBoundary>
|
|
|
|
|
</div>
|
2025-12-28 02:17:09 +02:00
|
|
|
</div>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-12-28 02:17:09 +02:00
|
|
|
|
2026-02-01 20:55:39 +02:00
|
|
|
{/* Desktop settings: windowed dialog with blur */}
|
2026-08-07 09:01:31 +03:00
|
|
|
{settingsWindowMounted ? (
|
|
|
|
|
<React.Suspense fallback={null}>
|
|
|
|
|
<SettingsWindow
|
|
|
|
|
open={isSettingsDialogOpen}
|
|
|
|
|
onOpenChange={setSettingsDialogOpen}
|
|
|
|
|
/>
|
|
|
|
|
</React.Suspense>
|
|
|
|
|
) : null}
|
2025-12-07 19:32:53 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
</div>
|
2025-12-14 02:29:46 +02:00
|
|
|
</DiffWorkerProvider>
|
2025-12-07 19:32:53 +02:00
|
|
|
);
|
|
|
|
|
};
|