Signage gets tabs: - Screens: every paired signage TV with what it plays (a playlist, or a schedule that wins over it), its shape and rotation, a warning when a playlist was made for the other shape; a link to pair one in Devices. - Schedules: lines (a playlist on days / between hours that may pass midnight / between dates, with a priority) and the playlist for the rest of the time; "now: …" per schedule; the screens on it. - Message and weather: the message of the day for every screen; the weather's town from a search (°C / °F), now / fetched at, "no forecast" when the server can't reach the service, fetch now, remove; says the weather needs internet and the widget hides without it. - e2e signage.mjs +6 (message saved, weather section, choosing a playlist and turning the picture move the TV, a schedule built in the manager plays what it picks now); a crash is reported as a failed check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
5.9 KiB
React
108 lines
5.9 KiB
React
// Signage (plan steps 5.6a-c): the venue's playlists for its TVs (pick one to edit its timeline and
|
|
// slides; make a new one for a landscape or a portrait screen), which screen plays what, the
|
|
// schedules, the message of the day and the weather's town: one tab each.
|
|
// Backend: /api/signage (routers/signage.py).
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
import toast from 'react-hot-toast'
|
|
import { Monitor, Plus, Smartphone } from 'lucide-react'
|
|
import { errorMessage } from '@xenia/api'
|
|
import { useTranslation } from '@xenia/i18n'
|
|
import { Button, Dialog, EmptyState, Field, Input, Select, Spinner } from '@xenia/ui'
|
|
import * as api from './signageApi'
|
|
import PlaylistEditor from './PlaylistEditor'
|
|
import SchedulesTab from './SchedulesTab'
|
|
import ScreensTab from './ScreensTab'
|
|
import SignageSettingsTab from './SignageSettingsTab'
|
|
|
|
const TABS = ['playlists', 'screens', 'schedules', 'settings']
|
|
|
|
export default function SignagePage() {
|
|
const { t } = useTranslation('manager')
|
|
const [list, setList] = useState(null)
|
|
const [current, setCurrent] = useState(null)
|
|
const [creating, setCreating] = useState(false)
|
|
const [tab, setTab] = useState('playlists')
|
|
|
|
const load = useCallback(async () => {
|
|
try { const l = await api.listPlaylists(); setList(l); return l } catch (err) { toast.error(errorMessage(err, t)); return null }
|
|
}, [t])
|
|
useEffect(() => { load().then(l => { if (l?.length) setCurrent(c => c ?? l[0].id) }) }, [load])
|
|
|
|
return (
|
|
<div className="p-4 md:p-6 grid gap-5 max-w-7xl" data-testid="signage-page">
|
|
<header className="grid gap-1">
|
|
<h1 className="text-heading font-semibold text-ink">{t('signage.pageTitle')}</h1>
|
|
<p className="text-body text-ink-2 max-w-3xl">{t('signage.intro')}</p>
|
|
</header>
|
|
<div className="flex flex-wrap gap-1 border-b border-line" role="tablist" aria-label={t('signage.pageTitle')}>
|
|
{TABS.map(k => (
|
|
<button key={k} type="button" role="tab" aria-selected={tab === k} onClick={() => setTab(k)} data-testid={`signage-tab-${k}`}
|
|
className={`px-3 py-2 -mb-px border-b-2 text-label font-medium transition-colors duration-fast
|
|
${tab === k ? 'border-accent text-accent-ink' : 'border-transparent text-ink-2 hover:text-ink'}`}>
|
|
{t(`signage.tabs.${k}`)}
|
|
</button>
|
|
))}
|
|
</div>
|
|
{tab === 'screens' && <ScreensTab />}
|
|
{tab === 'schedules' && <SchedulesTab />}
|
|
{tab === 'settings' && <SignageSettingsTab />}
|
|
{tab !== 'playlists' ? null : !list ? <div className="flex justify-center p-6"><Spinner /></div> : (
|
|
<div className="grid gap-5 xl:grid-cols-[14rem_1fr]">
|
|
<nav className="grid gap-2 content-start" aria-label={t('signage.playlists')}>
|
|
<span className="text-label font-medium text-ink-2">{t('signage.playlists')}</span>
|
|
<ul className="grid gap-1.5" data-testid="signage-playlists">
|
|
{list.map(p => {
|
|
const Icon = p.orientation === 'portrait' ? Smartphone : Monitor
|
|
return (
|
|
<li key={p.id}>
|
|
<button type="button" onClick={() => setCurrent(p.id)} aria-current={p.id === current ? 'true' : undefined}
|
|
data-testid="signage-playlist-item" data-name={p.name}
|
|
className={`w-full text-left px-3 py-2 rounded-control border flex items-center gap-2 transition-colors duration-fast
|
|
${p.id === current ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface hover:bg-surface-2 text-ink'}`}>
|
|
<Icon size={16} aria-label={t(`signage.orientations.${p.orientation}`)} />
|
|
<span className="flex-1 min-w-0 truncate text-label font-medium">{p.name}</span>
|
|
<span className="text-caption text-ink-3">{p.slide_count}</span>
|
|
</button>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setCreating(true)} data-testid="signage-new-playlist">{t('signage.newPlaylist')}</Button>
|
|
</nav>
|
|
<main className="min-w-0">
|
|
{current ? <PlaylistEditor key={current} playlistId={current} onChanged={load}
|
|
onDeleted={() => load().then(l => setCurrent(l?.[0]?.id ?? null))} />
|
|
: <EmptyState title={t('signage.noPlaylists')} description={t('signage.noPlaylistsHint')} />}
|
|
</main>
|
|
</div>
|
|
)}
|
|
{creating && <NewPlaylist onClose={() => setCreating(false)} onCreate={async body => {
|
|
try { const p = await api.createPlaylist(body); setCreating(false); await load(); setCurrent(p.id) } catch (err) { toast.error(errorMessage(err, t)) }
|
|
}} />}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function NewPlaylist({ onClose, onCreate }) {
|
|
const { t } = useTranslation('manager')
|
|
const [name, setName] = useState('')
|
|
const [orientation, setOrientation] = useState('landscape')
|
|
return (
|
|
<Dialog open size="sm" title={t('signage.newPlaylist')} onClose={onClose}
|
|
footer={<>
|
|
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
|
|
<Button disabled={!name.trim()} onClick={() => onCreate({ name: name.trim(), orientation })} data-testid="signage-create-playlist">{t('display.looks.create')}</Button>
|
|
</>}>
|
|
<div className="grid gap-3">
|
|
<Field label={t('signage.playlistName')}>
|
|
<Input value={name} autoFocus maxLength={80} onChange={e => setName(e.target.value)} placeholder={t('signage.playlistPlaceholder')} data-testid="signage-new-name" />
|
|
</Field>
|
|
<Field label={t('signage.orientation')} hint={t('signage.orientationHint')}>
|
|
<Select value={orientation} onChange={e => setOrientation(e.target.value)} data-testid="signage-new-orientation"
|
|
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
|
|
</Field>
|
|
</div>
|
|
</Dialog>
|
|
)
|
|
}
|