flyyt / src /MobileControlSheet.tsx
gpue's picture
Deploy 771c7d3cfb0b08d632f7fe3d02e59b7bcdff47c4
5a3b695 verified
Raw History Blame Contribute Delete
5.93 kB
import { useState } from "react";
import BrainActivity from "./BrainActivity";
import FlyChipStrip from "./FlyChipStrip";
import FlyControls from "./FlyControls";
import FlyList from "./FlyList";
import type { FlyInstanceData } from "./useFlyLayout";
import type { LiveFlyPositions } from "./useLiveFlyState";
import { useStatusSnapshot } from "./useStatusSnapshot";
// Exported so App.tsx can size the collapsed canvas as calc(100% - handle).
export const MOBILE_SHEET_HANDLE_HEIGHT = 48;
const TAB_BAR_HEIGHT = 40;
type SheetTab = "controls" | "flies" | "brain";
const TABS: { id: SheetTab; label: string }[] = [
{ id: "controls", label: "Controls" },
{ id: "flies", label: "Flies" },
{ id: "brain", label: "Brain" },
];
interface MobileControlSheetProps {
flies: FlyInstanceData[];
selectedFlyId: string | null;
onSelectFly: (id: string | null) => void;
joystickRef: React.RefObject<{ x: number; y: number }>;
wingSlidersRef: React.RefObject<{ left: number; right: number }>;
livePositionsRef: React.RefObject<LiveFlyPositions>;
expanded: boolean;
onToggleExpanded: () => void;
flying: boolean;
onToggleFlying: () => void;
altitudeLevelIndex: number;
onAltitudeChange: (index: number) => void;
}
export default function MobileControlSheet({
flies,
selectedFlyId,
onSelectFly,
joystickRef,
wingSlidersRef,
livePositionsRef,
expanded,
onToggleExpanded,
flying,
onToggleFlying,
altitudeLevelIndex,
onAltitudeChange,
}: MobileControlSheetProps) {
const statusSnapshot = useStatusSnapshot(flies, livePositionsRef);
const [activeTab, setActiveTab] = useState<SheetTab>("controls");
return (
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
overflow: "hidden",
background: "#14151d",
borderTop: "1px solid #2a2d3a",
fontFamily: "system-ui, sans-serif",
color: "#d8dae0",
paddingBottom: "calc(8px + env(safe-area-inset-bottom))",
}}
>
<div style={{ display: "flex", alignItems: "center", height: MOBILE_SHEET_HANDLE_HEIGHT, flexShrink: 0 }}>
<FlyChipStrip flies={flies} selectedFlyId={selectedFlyId} statusSnapshot={statusSnapshot} onSelectFly={onSelectFly} />
<button
onClick={onToggleExpanded}
aria-label={expanded ? "Collapse fly controls" : "Expand fly controls"}
style={{
width: 40,
height: MOBILE_SHEET_HANDLE_HEIGHT,
flexShrink: 0,
background: "transparent",
border: "none",
borderLeft: "1px solid #2a2d3a",
color: "#d8dae0",
cursor: "pointer",
fontSize: 16,
}}
>
{expanded ? "⌄" : "⌃"}
</button>
</div>
{expanded && (
<div style={{ flex: 1, minHeight: 0, overflow: "hidden", display: "flex", flexDirection: "column" }}>
<div style={{ display: "flex", height: TAB_BAR_HEIGHT, flexShrink: 0, borderBottom: "1px solid #2a2d3a" }}>
{TABS.map((tab) => (
<button
key={tab.id}
type="button"
onClick={() => setActiveTab(tab.id)}
style={{
flex: 1,
background: "transparent",
border: "none",
borderBottom: activeTab === tab.id ? "2px solid #8e56fc" : "2px solid transparent",
color: activeTab === tab.id ? "#d8dae0" : "#8b8d99",
font: "inherit",
fontSize: 13,
cursor: "pointer",
}}
>
{tab.label}
</button>
))}
</div>
{/* Each tab gets the FULL remaining height to itself -- avoids the
previous single-column layout, where stacking FlyControls +
FlyList + BrainActivity all at once needed flex-shrink to work
perfectly across every nested level to fit a compact sheet, and
in practice didn't: BrainActivity (last in the stack) ended up
laid out far below the visible, clipped area -- present in the
DOM, but never actually seen. */}
<div style={{ flex: 1, minHeight: 0, overflowY: "auto" }}>
{activeTab === "controls" && (
<>
<FlyControls
disabled={!selectedFlyId}
joystickRef={joystickRef}
wingSlidersRef={wingSlidersRef}
flying={flying}
onToggleFlying={onToggleFlying}
altitudeLevelIndex={altitudeLevelIndex}
onAltitudeChange={onAltitudeChange}
size="large"
/>
<button
type="button"
onClick={() => onSelectFly(null)}
disabled={!selectedFlyId}
style={{
display: "block",
width: "100%",
textAlign: "left",
padding: "8px 16px",
cursor: selectedFlyId ? "pointer" : "default",
background: "transparent",
border: "none",
color: selectedFlyId ? "inherit" : "#5a5d6b",
font: "inherit",
fontSize: 13,
}}
>
✕ Deselect
</button>
</>
)}
{activeTab === "flies" && (
<FlyList flies={flies} selectedFlyId={selectedFlyId} statusSnapshot={statusSnapshot} onSelectFly={onSelectFly} />
)}
{activeTab === "brain" && <BrainActivity selectedFlyId={selectedFlyId} livePositionsRef={livePositionsRef} />}
</div>
</div>
)}
</div>
);
}