Files
headquarter/apps/web/src/pages/TerminalPage.tsx
T
Developer e7f219f7c3 refactor: extract TerminalPage components
- Extract use-terminal-page hook for terminal state and effects
- Extract MobileTerminalView and DesktopTerminalView components
- Slim TerminalPage from 571 to 112 lines

Quality gates: tsc --noEmit passes, npm run build passes
2026-06-05 19:17:04 +00:00

113 lines
3.2 KiB
TypeScript

import React from "react";
import { useTerminalPage } from "../hooks/use-terminal-page";
import { MobileTerminalView } from "../components/features/terminal/MobileTerminalView";
import { DesktopTerminalView } from "../components/features/terminal/DesktopTerminalView";
export const TerminalPage: React.FC = () => {
const {
instanceId,
navigate,
isMobile,
isFullscreen,
setIsFullscreen,
terminalRefs,
headerAutoHide,
terminalStatuses,
showResetConfirm,
setShowResetConfirm,
showSpecialKeysPanel,
setShowSpecialKeysPanel,
activeModifier,
setActiveModifier,
isKeyboardOpen,
keyboardHeight,
sessions,
activeSessionId,
loading,
error,
handleFullscreenClick,
handleSelect,
handleClose,
handleCreate,
handleRename,
handleTerminalReady,
handleFontSizeChange,
handleSendKey,
handleReset,
sessionInfos,
} = useTerminalPage();
if (!instanceId) {
return (
<section className="stack">
<h1>Terminal</h1>
<p className="muted">No instance ID provided.</p>
</section>
);
}
const status = terminalStatuses[activeSessionId ?? "default"] ?? "connecting";
if (isMobile) {
return (
<MobileTerminalView
instanceId={instanceId}
sessions={sessions}
sessionInfos={sessionInfos}
activeSessionId={activeSessionId ?? ""}
terminalRefs={terminalRefs}
status={status}
error={error}
loading={loading}
isKeyboardOpen={isKeyboardOpen}
keyboardHeight={keyboardHeight}
isVisible={headerAutoHide.isVisible}
activeModifier={activeModifier}
showSpecialKeysPanel={showSpecialKeysPanel}
onToggleHeader={headerAutoHide.toggle}
onNavigateBack={() => navigate("/sessions")}
onFontSizeChange={handleFontSizeChange}
onSelect={handleSelect}
onClose={handleClose}
onCreate={handleCreate}
onRename={handleRename}
onTerminalReady={handleTerminalReady}
onSendKey={handleSendKey}
onModifierChange={setActiveModifier}
onShowSpecialKeys={() => setShowSpecialKeysPanel(true)}
onHideSpecialKeys={() => setShowSpecialKeysPanel(false)}
onKeepFocus={() => {
/* focus handled by ref */
}}
/>
);
}
return (
<DesktopTerminalView
instanceId={instanceId}
sessions={sessions}
sessionInfos={sessionInfos}
activeSessionId={activeSessionId ?? ""}
terminalRefs={terminalRefs}
isFullscreen={isFullscreen}
status={status}
error={error}
loading={loading}
showResetConfirm={showResetConfirm}
onFullscreenClick={handleFullscreenClick}
onSelect={handleSelect}
onClose={handleClose}
onCreate={handleCreate}
onRename={handleRename}
onNavigateBack={() => navigate("/sessions")}
onToggleFullscreen={() => setIsFullscreen((p) => !p)}
onFontSizeChange={handleFontSizeChange}
onShowResetConfirm={() => setShowResetConfirm(true)}
onHideResetConfirm={() => setShowResetConfirm(false)}
onReset={handleReset}
onTerminalReady={handleTerminalReady}
/>
);
};