add reboot command

This commit is contained in:
legop3
2026-02-18 15:09:36 -05:00
parent eb52c8c6ac
commit 40e21d4ac5
11 changed files with 211 additions and 129 deletions
+25 -1
View File
@@ -10,9 +10,11 @@ const MODES = [
];
export default function AdminPanel() {
const { session, lockRover, setMode, requestControl, setCommunityGoal, setAdminReason, adminLogs } = useSession();
const { session, lockRover, setMode, requestControl, setCommunityGoal, setAdminReason, rebootRover, adminLogs } =
useSession();
const roster = useMemo(() => session?.roster ?? [], [session?.roster]);
const [lockStates, setLockStates] = useState({});
const [rebootStates, setRebootStates] = useState({});
const health = session?.health || null;
const currentGoal = session?.communityGoal?.text || '';
const goalUpdatedAt = session?.communityGoal?.updatedAt || null;
@@ -54,6 +56,20 @@ export default function AdminPanel() {
}
};
const handleReboot = async (rover) => {
if (!rover?.id) return;
const ok = window.confirm(`Reboot rover "${rover.name || rover.id}" now?`);
if (!ok) return;
setRebootStates((prev) => ({ ...prev, [rover.id]: true }));
try {
await rebootRover(rover.id);
} catch (err) {
alert(err.message);
} finally {
setRebootStates((prev) => ({ ...prev, [rover.id]: false }));
}
};
const handleGoalSave = async () => {
try {
await setCommunityGoal(goalDraft);
@@ -176,6 +192,14 @@ export default function AdminPanel() {
<button type="button" onClick={() => handleForceControl(rover.id)} className="button-dark">
Force
</button>
<button
type="button"
onClick={() => handleReboot(rover)}
disabled={Boolean(rebootStates[rover.id])}
className="button-danger disabled:cursor-not-allowed disabled:opacity-60"
>
{rebootStates[rover.id] ? 'Rebooting...' : 'Reboot'}
</button>
</div>
)}
/>
+3
View File
@@ -20,6 +20,7 @@ const SessionContext = createContext({
triggerReplay: async () => {},
setCommunityGoal: async () => {},
setAdminReason: async () => {},
rebootRover: async () => {},
});
function useAckEmitter(socket) {
@@ -117,6 +118,8 @@ export function SessionProvider({ children }) {
triggerReplay: (sources = []) => emitWithAck('replay:trigger', { sources }),
setCommunityGoal: (text) => emitWithAck('communityGoal:set', { text }),
setAdminReason: (text) => emitWithAck('adminReason:set', { text }),
rebootRover: (roverId) =>
emitWithAck('command', { roverId, type: 'reboot', data: { reboot: {} } }),
pushAlert: (alert) =>
setAlerts((prev) => [
...prev.slice(-49),