feat(manager): signage screens, schedules, the message of the day and the weather's town (platform-v2 step 5.6c)
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>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// Signage → Message and weather (plan step 5.6c): the message of the day (one place for every
|
||||
// screen, at once) and the weather's town (picked from a search; the weather needs internet, and
|
||||
// without it the widget is simply hidden on the TVs).
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { CloudOff, RefreshCw, Search } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Field, Input, Select, Spinner } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
|
||||
export default function SignageSettingsTab() {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatDateTime } = useFormat()
|
||||
const { language: lang } = useLanguage()
|
||||
const [message, setMessage] = useState(null)
|
||||
const [savedMessage, setSavedMessage] = useState('')
|
||||
const [status, setStatus] = useState(null)
|
||||
const [q, setQ] = useState('')
|
||||
const [places, setPlaces] = useState(null)
|
||||
const [units, setUnits] = useState('celsius')
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const [m, w] = await Promise.all([api.getMessage(), api.weatherStatus()])
|
||||
setMessage(m.text || ''); setSavedMessage(m.text || ''); setStatus(w)
|
||||
if (w.place?.units) setUnits(w.place.units)
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}, [t])
|
||||
useEffect(() => { load() }, [load])
|
||||
const act = async (fn, done) => {
|
||||
setBusy(true)
|
||||
try { const r = await fn(); if (done) toast.success(done); return r } catch (err) { toast.error(errorMessage(err, t)); return null } finally { setBusy(false) }
|
||||
}
|
||||
if (message === null) return <div className="flex justify-center p-6"><Spinner /></div>
|
||||
const w = status?.weather
|
||||
|
||||
return (
|
||||
<div className="grid gap-5 max-w-3xl" data-testid="signage-settings">
|
||||
<section className="rounded-card border border-line bg-surface p-4 grid gap-3">
|
||||
<h2 className="text-body font-semibold text-ink">{t('signage.settings.message')}</h2>
|
||||
<p className="text-label text-ink-2">{t('signage.settings.messageHint')}</p>
|
||||
<div className="flex gap-2 items-start">
|
||||
<Input value={message} maxLength={200} onChange={e => setMessage(e.target.value)} className="flex-1" aria-label={t('signage.settings.message')} data-testid="signage-message" />
|
||||
<Button disabled={busy || message.trim() === savedMessage.trim()} data-testid="signage-message-save"
|
||||
onClick={() => act(() => api.putMessage(message.trim()), t('settings.saved')).then(r => { if (r) setSavedMessage(r.text || '') })}>{t('fees.save')}</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-weather">
|
||||
<h2 className="text-body font-semibold text-ink">{t('signage.settings.weather')}</h2>
|
||||
<p className="text-label text-ink-2 flex items-start gap-1.5"><CloudOff size={16} className="shrink-0 mt-0.5" aria-hidden="true" />{t('signage.settings.weatherHint')}</p>
|
||||
{status?.place ? (
|
||||
<div className="grid gap-1 text-label" data-testid="signage-weather-place">
|
||||
<span className="text-ink"><strong>{status.place.name}</strong> · {t(`signage.settings.units.${status.place.units}`)}</span>
|
||||
{w ? <span className="text-ink-2" data-testid="signage-weather-now">{t('signage.settings.now', { temp: Math.round(w.temperature), unit: status.place.units === 'fahrenheit' ? '°F' : '°C', at: status.fetched_at ? formatDateTime(new Date(status.fetched_at * 1000)) : '' })}</span>
|
||||
: <span className="text-warning-ink" data-testid="signage-weather-none">{t(status.error ? 'signage.settings.noForecast' : 'signage.settings.waiting')}</span>}
|
||||
<div className="flex gap-2 pt-1">
|
||||
<Button size="sm" variant="secondary" icon={<RefreshCw size={14} />} disabled={busy} onClick={() => act(api.refreshWeather).then(r => r && setStatus(r))}>{t('signage.settings.refresh')}</Button>
|
||||
<Button size="sm" variant="ghost" disabled={busy} onClick={() => act(api.forgetWeatherPlace, t('settings.saved')).then(r => r && setStatus(r))}>{t('signage.settings.forget')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : <p className="text-label text-ink-3">{t('signage.settings.noPlace')}</p>}
|
||||
<div className="grid gap-2">
|
||||
<div className="flex gap-2 items-end flex-wrap">
|
||||
<Field label={t('signage.settings.town')} className="flex-1 min-w-[12rem]">
|
||||
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('signage.settings.townPlaceholder')} data-testid="signage-weather-search" />
|
||||
</Field>
|
||||
<Field label={t('signage.settings.unitsLabel')}>
|
||||
<Select value={units} onChange={e => setUnits(e.target.value)} options={['celsius', 'fahrenheit'].map(u => ({ value: u, label: t(`signage.settings.units.${u}`) }))} />
|
||||
</Field>
|
||||
<Button variant="secondary" icon={<Search size={16} />} disabled={busy || q.trim().length < 2} data-testid="signage-weather-find"
|
||||
onClick={() => act(() => api.weatherPlaces(q.trim(), lang === 'el' ? 'el' : 'en')).then(r => r && setPlaces(r))}>{t('signage.settings.find')}</Button>
|
||||
</div>
|
||||
{places && (places.length === 0 ? <p className="text-label text-ink-3">{t('media.noMatch')}</p> : (
|
||||
<ul className="grid gap-1" data-testid="signage-weather-places">
|
||||
{places.map((p, i) => (
|
||||
<li key={i}>
|
||||
<button type="button" className="w-full text-left px-2 py-1.5 rounded-control hover:bg-surface-2 text-label text-ink" data-testid="signage-weather-place-pick"
|
||||
onClick={() => act(() => api.setWeatherPlace({ name: p.name, latitude: p.latitude, longitude: p.longitude, units }), t('settings.saved'))
|
||||
.then(r => { if (r) { setStatus(r); setPlaces(null); setQ('') } })}>
|
||||
<strong>{p.name}</strong> <span className="text-ink-3">{[p.region, p.country].filter(Boolean).join(', ')}</span>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user