({ projectWindow }: { projectWindow: ProjectWindow<WindowCarry> })
| 760 | } |
| 761 | |
| 762 | function ProjectWindowView({ projectWindow }: { projectWindow: ProjectWindow<WindowCarry> }): JSX.Element { |
| 763 | const carried = projectWindow.carried; |
| 764 | const [workspace, setWorkspace] = useState<Workspace>(() => { |
| 765 | try { |
| 766 | // A project switch keeps the workspace in view; Back and Forward restore the one of their entry (K24). |
| 767 | const requested = new URLSearchParams(window.location.search).get('workspace') ?? carried?.workspace ?? null; |
| 768 | let saved: string | null = null; |
| 769 | try { saved = localStorage.getItem('cbm.workspace'); } catch { /* URL navigation works without storage. */ } |
| 770 | return initialWorkspace(requested, saved); |
| 771 | } catch { return 'architecture'; } |
| 772 | }); |
| 773 | const changeWorkspace = (value: Workspace): void => { |
| 774 | value = allowedWorkspace(value); |
| 775 | if (value !== workspace) { |
| 776 | setProactiveSelection(undefined); setChatGraphSelection(undefined); setChatAttachment(undefined); |
| 777 | } |
| 778 | setWorkspace(value); |
| 779 | try { localStorage.setItem('cbm.workspace', value); } catch { /* Session-only preference. */ } |
| 780 | }; |
| 781 | // The address always names the workspace in view, also one carried over a project switch, so a reload keeps it (A5). |
| 782 | useParamInAddress('workspace', workspace); |
| 783 | const [welcomeOpen, setWelcomeOpen] = useState(() => { |
| 784 | try { return localStorage.getItem('cbm.workspace.setup') !== 'done'; } catch { return false; } |
| 785 | }); |
| 786 | // The agent's lamp and the chat stay as they were across a project switch (K24). |
| 787 | const [browserAiOpen, setBrowserAiOpen] = useState(carried?.chatOpen ?? false); |
| 788 | const [localAgentState, setLocalAgentState] = useState<'off' | 'loading' | 'active' | 'busy' | 'error'>(carried?.agentState ?? 'off'); |
| 789 | const [agentSettingsRequest, setAgentSettingsRequest] = useState(0); |
| 790 | const [agentModelName, setAgentModelName] = useState(carried?.agentModelName ?? ''); |
| 791 | const agentHasOpened = useRef(carried?.agentHasOpened ?? false); |
| 792 | useEffect(() => { |
| 793 | projectWindow.report({ workspace, chatOpen: browserAiOpen, agentState: localAgentState, agentModelName, agentHasOpened: agentHasOpened.current }); |
| 794 | }); |
| 795 | const onAgentStateChange = useCallback((state: 'off' | 'loading' | 'active' | 'busy' | 'error') => { |
| 796 | setLocalAgentState(state); |
| 797 | if ((state === 'active' || state === 'busy') && !agentHasOpened.current) { |
| 798 | agentHasOpened.current = true; setBrowserAiOpen(true); |
| 799 | } |
| 800 | }, []); |
| 801 | const openAgentSettings = () => { setAgentSettingsRequest(value => value + 1); }; |
| 802 | const [codeDetailsOpen, setCodeDetailsOpen] = useState(false); |
| 803 | const [readerSelection, setReaderSelection] = useState<ReaderSelection>(); |
| 804 | const [pinnedCode, setPinnedCode] = useState<SelectedCodeSnapshot>(); |
| 805 | const [fileSymbols, setFileSymbols] = useState<FileSymbolResult & { project: string; path: string; status: 'loading' | 'ready' | 'error' }>({ project: '', path: '', symbols: [], message: '', status: 'ready' }); |
| 806 | const [chatAttachment, setChatAttachment] = useState<BrowserChatAttachment>(); |
| 807 | const [chatGraphSelection, setChatGraphSelection] = useState<BrowserChatContext>(); |
| 808 | const [proactiveSelection, setProactiveSelection] = useState<{ scope: string; context: BrowserChatContext }>(); |
| 809 | const [galaxySelection, setGalaxySelection] = useState<GraphNode>(); |
| 810 | const [galaxySelectionProject, setGalaxySelectionProject] = useState(''); |
| 811 | const finishSetup = (): void => { |
| 812 | setWelcomeOpen(false); |
| 813 | setWhyDismissed(true); |
| 814 | try { localStorage.setItem('cbm.workspace.setup', 'done'); } catch { /* Session-only preference. */ } |
| 815 | }; |
| 816 | const guidance: Guidance = 'brief'; |
| 817 | // Requests of this window end with it: a switch to another project aborts them (K24). |
| 818 | const client = useMemo(() => new RpcIntelligenceClient({ signal: projectWindow.signal }), [projectWindow.signal]); |
| 819 | const api = useMemo(() => new AtlasApi({ signal: projectWindow.signal }), [projectWindow.signal]); |
nothing calls this directly
no test coverage detected