Harden dashboard realtime state and controls

This commit is contained in:
jjbrunton committed 2026-08-08 15:41:58 +01:00
1 parent 4b3f00729f
commit d108903174
21 files changed
+422 -29

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import type { RealtimeConnectionSnapshot } from '../features/operations/realtime-client.js';
interface ShellStatusInput {
stats?: { isRunning: boolean; dryRunMode: boolean; invitationCooldown: { reason: string } | null };
reddit?: { ready: boolean; loggedIn?: boolean; status?: string; error?: string };
realtime: RealtimeConnectionSnapshot;
sync?: { syncing: boolean; syncingKind?: string | null };
}
export interface ShellStatus {
bot: string;
reddit: string;
realtime: string;
cooldown: string | null;
sync: string;
controlAction: 'start' | 'stop';
controlDisabled: boolean;
}
function sentence(value: string): string { return value.charAt(0).toUpperCase() + value.slice(1); }
export function deriveShellStatus(input: ShellStatusInput): ShellStatus {
const stats = input.stats;
const realtime = input.realtime.status === 'connected'
? 'Realtime connected'
: `Realtime ${input.realtime.status}${input.realtime.isStale ? ' (stale)' : ''}`;
const reddit = input.reddit?.ready
? input.reddit.loggedIn ? `Reddit ${input.reddit.status ?? 'authenticated'}` : 'Reddit login required'
: 'Reddit session unavailable';
return {
bot: stats ? `${stats.isRunning ? 'Running' : 'Stopped'}${stats.dryRunMode ? ' (dry run)' : ''}` : 'Bot state unavailable',
reddit,
realtime,
cooldown: stats?.invitationCooldown?.reason ?? null,
sync: input.sync?.syncing ? `${sentence(input.sync.syncingKind ?? 'unknown')} sync active` : 'No active sync',
controlAction: stats?.isRunning ? 'stop' : 'start',
controlDisabled: stats === undefined,
};
}