feat(preview): add server/port dropdown to address bar

This commit is contained in:
2026-06-12 12:20:48 -07:00
parent 5ed10c4077
commit cd26dd807f
3 changed files with 134 additions and 43 deletions

View File

@@ -71,7 +71,8 @@ export default function PreviewTab() {
)
.sort((a, b) => a.port - b.port); // sort ports ascending
const [selectedPort, setSelectedPort] = useState<number>(3000);
const selectedPort = usePreviewToolbarStore((s) => s.selectedPort);
const setSelectedPort = usePreviewToolbarStore((s) => s.setSelectedPort);
// Auto-select logic if selectedPort is not in validPreviews
useEffect(() => {
@@ -83,7 +84,7 @@ export default function PreviewTab() {
validPreviews.find((p) => p.port === 3000) ?? validPreviews[0];
if (fallback) setSelectedPort(fallback.port);
}
}, [validPreviews, selectedPort]);
}, [validPreviews, selectedPort, setSelectedPort]);
// Derive the currently selected preview
const activePreview = validPreviews.find((p) => p.port === selectedPort);
@@ -232,27 +233,6 @@ export default function PreviewTab() {
return (
<div style={canvas}>
{validPreviews.length > 1 && (
<div style={portPickerWrap}>
{validPreviews.map((p) => (
<button
key={p.id}
onClick={() => setSelectedPort(p.port)}
style={
selectedPort === p.port ? portButtonActive : portButtonInactive
}
>
<div
style={p.state === "running" ? dotRunning : dotStarting}
className={p.state === "starting" ? "animate-pulse" : ""}
/>
{p.name && p.name !== `port-${p.port}`
? p.name
: `Port ${p.port}`}
</button>
))}
</div>
)}
<div
style={{
flex: 1,