feat(ui): migrate routes and app shell to controller-driven state

This commit is contained in:
2026-03-02 14:15:00 +00:00
parent 13e77294be
commit 531e77d900
8 changed files with 660 additions and 30 deletions

View File

@@ -1,8 +1,243 @@
<script lang="ts">
import ClientScreen from '$lib/sim/screens/ClientScreen.svelte';
// @ts-nocheck
import AppChrome from '$lib/sim/ui/AppChrome.svelte';
import { appController } from '$lib/app/controller';
import { appState } from '$lib/app/store';
let clientVideoElement: HTMLVideoElement | null = null;
$effect(() => {
appController.setClientVideoElement(clientVideoElement);
});
const statusDotClass = (status: string) =>
status?.toLowerCase() === 'online' ? 'bg-green-500' : 'bg-gray-600';
const isCameraLive = (cameraDeviceId: string) => {
const sessionId = $appState.cameraSessions?.[cameraDeviceId];
if (!sessionId) return false;
return $appState.connectedStreamSessionIds.includes(sessionId);
};
const activeCameraLabel = () => {
const linked = $appState.linkedCameras.find((camera) => camera.cameraDeviceId === $appState.activeCameraDeviceId);
return linked?.cameraName || linked?.cameraDeviceId || 'Live Feed Viewer';
};
</script>
<svelte:window onclick={() => appController.closeLinkedCameraMenu()} />
<AppChrome pageKey="client">
<ClientScreen />
<section id="screen-home-client" class="flex flex-col gap-12 max-w-7xl mx-auto h-full">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold text-white tracking-tight">Client Dashboard</h2>
<div class="flex gap-3">
<button
id="linkCameraBtn"
class="btn btn-outline border-white/10 text-gray-300 hover:text-white hover:bg-white/5 rounded-xl gap-2 shadow-none"
onclick={() => appController.linkCamera()}
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
Link Camera
</button>
<button
id="refreshClientBtn"
class="btn btn-ghost btn-square rounded-xl bg-white/5 border border-white/5 hover:bg-white/10"
aria-label="Refresh linked cameras"
title="Refresh linked cameras"
onclick={() => appController.refreshClientData()}
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
/>
</svg>
</button>
</div>
</div>
<div class="glass-card rounded-3xl border border-white/5 p-5 shrink-0 mb-4">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-wider mb-4">Your Cameras</h3>
<div id="linkedCamerasList" class="flex overflow-x-auto gap-4 pb-2 snap-x">
{#if $appState.linkedCameras.length === 0}
<div class="w-full text-center py-6 bg-black/20 rounded-2xl border border-dashed border-white/10">
<p class="text-gray-500 text-sm">No cameras linked yet</p>
</div>
{:else}
{#each $appState.linkedCameras as link (link.id)}
<div
role="button"
tabindex="0"
class="min-w-[240px] max-w-[240px] bg-gray-900/60 rounded-xl border border-white/5 overflow-hidden flex-shrink-0 cursor-pointer hover:border-blue-500/50 transition-colors text-left"
onclick={() => appController.selectCamera(link.cameraDeviceId)}
onkeydown={(event) => {
if (event.key === 'Enter' || event.key === ' ') appController.selectCamera(link.cameraDeviceId);
}}
>
<div class="relative overflow-hidden bg-black/40 border-b border-white/5 aspect-video">
{#if $appState.activeCameraDeviceId === link.cameraDeviceId}
<div class="absolute inset-0 flex flex-col items-center justify-center gap-2 text-blue-400 bg-blue-500/10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
</svg>
<p class="text-[10px] font-medium uppercase tracking-wider">Viewing</p>
</div>
{:else}
<div class="absolute inset-0 flex flex-col items-center justify-center gap-2 text-gray-500 hover:text-gray-300 transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
<p class="text-[10px]">{isCameraLive(link.cameraDeviceId) ? 'Live Stream Active' : 'Click to view'}</p>
</div>
{/if}
</div>
<div class="px-3 py-3">
<div class="flex items-start justify-between gap-2">
<div class="flex items-center gap-2 min-w-0">
<div class="w-2 h-2 rounded-full shrink-0 {statusDotClass(link.cameraStatus)}"></div>
<div class="min-w-0">
<p class="text-xs font-bold text-gray-200 truncate" title={link.cameraName || link.cameraDeviceId}>
{link.cameraName || link.cameraDeviceId}
</p>
<p class="text-[10px] text-gray-400 capitalize">{link.cameraStatus || 'offline'}</p>
</div>
</div>
<div class="relative">
<button
type="button"
class="btn btn-ghost btn-xs btn-circle text-gray-400 hover:text-white"
aria-label="Camera options"
onclick={(event) => {
event.stopPropagation();
appController.toggleLinkedCameraMenu(link.id);
}}
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<circle cx="10" cy="4" r="1.6" />
<circle cx="10" cy="10" r="1.6" />
<circle cx="10" cy="16" r="1.6" />
</svg>
</button>
<div class="{($appState.openLinkedCameraMenuId === link.id ? '' : 'hidden ')}absolute right-0 bottom-8 z-20 w-28 overflow-hidden rounded-lg border border-white/10 bg-gray-900/95 shadow-xl backdrop-blur">
<button
type="button"
class="w-full px-3 py-2 text-left text-xs text-gray-200 hover:bg-white/10"
onclick={(event) => {
event.stopPropagation();
appController.renameLinkedCamera(link.cameraDeviceId);
}}
>
Rename
</button>
<button
type="button"
class="w-full px-3 py-2 text-left text-xs text-red-300 hover:bg-red-500/10"
onclick={(event) => {
event.stopPropagation();
appController.deleteLinkedCamera(link.id);
}}
>
Delete
</button>
</div>
</div>
</div>
</div>
</div>
{/each}
{/if}
</div>
</div>
<div class="flex flex-col xl:flex-row gap-8 flex-1 min-h-0">
<div
id="clientStreamViewerWrapper"
class="flex-1 glass-card rounded-3xl overflow-hidden border border-white/10 flex flex-col shadow-xl min-h-[400px] {$appState.activeCameraDeviceId ? '' : 'hidden'}"
>
<div class="px-5 py-4 border-b border-white/5 bg-black/20 flex justify-between items-center">
<div class="flex items-center gap-3">
<span class="w-2 h-2 rounded-full bg-red-500 animate-[pulse_2s_ease-in-out_infinite] {isCameraLive($appState.activeCameraDeviceId) ? '' : 'hidden'}" id="clientLiveDot"></span>
<h3 class="font-medium text-white tracking-wide" id="clientStreamViewerTitle">Live Feed: {activeCameraLabel()}</h3>
</div>
<button
id="closeStreamViewerBtn"
class="btn btn-ghost btn-sm btn-circle text-gray-400 hover:text-white"
aria-label="Close stream viewer"
title="Close stream viewer"
onclick={() => appController.closeStreamViewer()}
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div id="clientStreamContainer" class="flex-1 bg-black relative flex items-center justify-center">
<video
id="clientStreamVideo"
class="absolute inset-0 w-full h-full object-contain {$appState.clientStreamMode === 'video' ? '' : 'hidden'}"
playsinline
bind:this={clientVideoElement}
></video>
{#if $appState.clientFallbackFrame}
<img
id="clientStreamImage"
class="absolute inset-0 w-full h-full object-contain {$appState.clientStreamMode === 'image' ? '' : 'hidden'}"
src={$appState.clientFallbackFrame}
alt="Live stream frame"
/>
{/if}
<div id="clientStreamPlaceholder" class="flex flex-col items-center gap-4 animate-pulse {$appState.clientStreamMode === 'none' || $appState.clientStreamMode === 'connecting' || $appState.clientStreamMode === 'unavailable' ? '' : 'hidden'}">
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
></path>
</svg>
<p class="text-sm font-medium text-gray-500 tracking-wide uppercase">{$appState.clientPlaceholderText}</p>
</div>
</div>
</div>
<div class="xl:w-96 shrink-0 flex flex-col gap-6 overflow-y-auto pr-2">
<div class="glass-card rounded-3xl border border-white/5 p-5 flex-1">
<h3 class="text-xs font-bold text-gray-400 uppercase tracking-wider mb-4">Recent Recordings</h3>
<div id="recordingsList" class="space-y-3">
{#if $appState.recordings.length === 0}
<div class="text-center py-4 bg-gray-900/30 rounded-xl">
<p class="text-gray-600 text-xs text-center">No recordings found</p>
</div>
{:else}
{#each $appState.recordings.slice(0, 5) as recording (recording.id)}
<div class="flex items-center justify-between p-3 bg-gray-900/40 rounded-lg border border-white/5 hover:bg-gray-800 transition-colors">
<div class="flex flex-col">
<span class="text-xs font-medium text-gray-300">{new Date(recording.createdAt).toLocaleString()}</span>
<span class="text-[10px] text-gray-500">
{recording.durationSeconds != null ? `${recording.durationSeconds}s duration` : 'Duration pending'} · {recording.status ?? 'unknown'}
</span>
</div>
<button
class="btn btn-xs btn-outline border-white/10 text-gray-400"
disabled={recording.status !== 'ready'}
onclick={() => appController.openRecording(recording.id)}
>
View
</button>
</div>
{/each}
{/if}
</div>
</div>
</div>
</div>
</section>
</AppChrome>