NeonClary
Make simulator runnable on first click + editable commands
7f237a3
Raw
History Blame Contribute Delete
2.36 kB
import React from 'react';
import { Activity, Play } from 'lucide-react';
export default function SensorInputForm({
sensors, channel, value, onChannelChange, onValueChange,
pending, onQueue, onRun, running,
}) {
const handleQueue = (e) => {
e.preventDefault();
if (!channel || value === '') return;
onQueue();
};
const canRun = !running && (pending.length > 0 || (channel && value !== ''));
const runLabel = pending.length > 0
? `Run Simulation (${pending.length} queued)`
: 'Run Simulation';
return (
<div className="decidron-panel">
<h2>Sensor Input</h2>
<p className="panel-hint">
A reading is pre-filled — just press <strong>Run Simulation</strong>
to see the network react. Use <strong>Queue</strong> to stack
several inputs before running.
</p>
<form onSubmit={handleQueue}>
<div className="decidron-row">
<div className="decidron-field" style={{ flex: 1 }}>
<label>Channel</label>
<select value={channel} onChange={(e) => onChannelChange(e.target.value)}>
{sensors.map((s) => (
<option key={s.id} value={s.id}>{s.label}</option>
))}
</select>
</div>
<div className="decidron-field" style={{ flex: 1 }}>
<label>Value</label>
<input
type="text"
value={value}
placeholder="e.g. 97"
onChange={(e) => onValueChange(e.target.value)}
/>
</div>
<button type="submit" className="decidron-btn secondary">
<Activity size={14} style={{ marginRight: 4, verticalAlign: 'middle' }} />
Queue
</button>
</div>
</form>
{pending.length > 0 && (
<ul className="decidron-pending">
{pending.map((p, i) => (
<li key={i}>{p.channel}: {p.value}</li>
))}
</ul>
)}
<div className="decidron-row" style={{ marginTop: '0.5rem' }}>
<button
type="button"
className="decidron-btn"
onClick={onRun}
disabled={!canRun}
>
<Play size={14} style={{ marginRight: 4, verticalAlign: 'middle' }} />
{running ? 'Running…' : runLabel}
</button>
</div>
</div>
);
}