La radio no se dibuja para un invitado ni contra un servidor viejo
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s

Las emisoras las busca el servidor, así que dos situaciones que no son bugs se veían
como uno: sin sesión (el modo invitado nunca habla con la api) y una api más vieja
que la app —se despliegan por separado, y un deploy que reconstruyó `web` y no el
contenedor de la api es una pantalla cuyos pedidos fallan todos.

Ahora la sección lo dice y no pide nada en ninguno de los dos casos. Para poder
distinguirlos, `radio` entra en `features` (`GET /api/config`), que es exactamente
para lo que existe esa lista, y queda documentado en la especificación junto con
`features` entero —que hasta ahora no estaba.

De paso: la fila y la barra caen al marcador de posición cuando el logo o la portada
no cargan, que es el caso de una parte del directorio.
This commit is contained in:
dsantillan committed 2026-09-23 20:45:21 -04:00
1 parent 8f26b536fd
commit a3e13df279
7 files changed
+108 -25

No files matched your search

+2
View File
@@ -1427,6 +1427,8 @@ export default {
'Saved to your stations': 'Guardada en tus emisoras',
'Nothing playing. Pick a station below.': 'No hay nada sonando. Elegí una emisora abajo.',
'These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.': 'Son radios públicas: no se descarga nada y el audio va directo de la emisora a tu teléfono. Las primeras de cada género son emisoras sin publicidad.',
'The radio comes from your server, so it needs a profile: sign in and the stations appear here.': 'La radio viene de tu servidor, así que necesita un perfil: entrá a tu cuenta y las emisoras aparecen acá.',
'Your server has not been updated for the radio yet: it is the server that finds the stations, and this app is newer than it. Restarting it should be enough.': 'Tu servidor todavía no se actualizó para la radio: las emisoras las busca el servidor, y esta app es más nueva que él. Reiniciarlo debería alcanzar.',
'What arrived last': 'Qué llegó en el último envío',
'Datapoints in the last sync': 'Datos en el último envío',
'How they were stamped': 'Cómo vienen marcados',
+39 -22
View File
@@ -102,8 +102,17 @@ function RadioSection() {
const playRadio = useUI(s => s.playRadio)
const toast = useUI(s => s.toast)
const S = useStore(s => s.S)
const user = useStore(s => s.user)
const cfg = useStore(s => s.config)
const addStation = useStore(s => s.addStation)
const removeStation = useStore(s => s.removeStation)
/* The list comes from the server, so two situations have to be told apart from a bug rather than
shown as one: nobody is signed in (guest mode never talks to the api at all), and the api is
older than the app — they ship separately, so a deploy that refreshed `web` and not the api
container leaves a screen whose every request is a 401/404. Both are quiet lines instead of a
toast, and no request is made in either case. */
const staleApi = !!cfg && Array.isArray(cfg.features) && !cfg.features.includes('radio')
const canRadio = !!user && !staleApi
const [genres, setGenres] = useState(null)
const [genre, setGenre] = useState(null)
const [stations, setStations] = useState(null)
@@ -125,7 +134,7 @@ function RadioSection() {
.catch(e => toast(e.message))
.finally(() => setBusy(false))
}
useEffect(() => { load(null) }, [])
useEffect(() => { if (canRadio) load(null) }, [canRadio])
const play = station => {
// Synchronous on purpose: `play()` has to happen inside this tap for iOS to allow it.
@@ -154,27 +163,35 @@ function RadioSection() {
return <>
<h4 className="sec">{t('Radio')}{stations ? <span className="vh-window"> · {t('{0} stations', stations.length)}</span> : null}</h4>
<div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
{t('These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.')}
</div>
<div className="chips" style={{ marginBottom: 10 }}>
{(genres || []).map(g => <button key={g.key}
className={'chip' + (genre === g.key ? ' on' : '')}
onClick={() => load(g.key)}>{g.label}</button>)}
</div>
{saved.length > 0 && <>
<div className="mus-sub-h">{t('Saved stations')}</div>
{saved.map(st => row(st))}
</>}
{busy && !stations && <div className="small dim" style={{ margin: '0 2px 10px' }}>{t('Loading stations…')}</div>}
{stations && stations.map(st => row(st))}
{stations && !stations.length && <div className="small dim" style={{ margin: '0 2px 10px' }}>
{t('That station is not answering. Try another one.')}
</div>}
{radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>
{radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)}
</div>}
{!radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>{t('Nothing playing. Pick a station below.')}</div>}
{!canRadio
? <div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
{staleApi
? t('Your server has not been updated for the radio yet: it is the server that finds the stations, and this app is newer than it. Restarting it should be enough.')
: t('The radio comes from your server, so it needs a profile: sign in and the stations appear here.')}
</div>
: <>
<div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
{t('These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.')}
</div>
<div className="chips" style={{ marginBottom: 10 }}>
{(genres || []).map(g => <button key={g.key}
className={'chip' + (genre === g.key ? ' on' : '')}
onClick={() => load(g.key)}>{g.label}</button>)}
</div>
{saved.length > 0 && <>
<div className="mus-sub-h">{t('Saved stations')}</div>
{saved.map(st => row(st))}
</>}
{busy && !stations && <div className="small dim" style={{ margin: '0 2px 10px' }}>{t('Loading stations…')}</div>}
{stations && stations.map(st => row(st))}
{stations && !stations.length && <div className="small dim" style={{ margin: '0 2px 10px' }}>
{t('That station is not answering. Try another one.')}
</div>}
{radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>
{radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)}
</div>}
{!radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>{t('Nothing playing. Pick a station below.')}</div>}
</>}
</>
}
+25 -1
View File
@@ -44,7 +44,13 @@ beforeEach(() => {
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
useStore.setState(s => ({ S: { ...s.S, music: { user: '', playlists: [] } } }))
useStore.setState(s => ({
S: { ...s.S, music: { user: '', playlists: [] } },
// The radio section is server-backed: it draws nothing for a guest or against an api older
// than the app. Every test here starts signed in, on a server that answers.
user: { id: 'u1', name: 'Test' },
config: null
}))
})
afterEach(() => { act(() => root.unmount()); host.remove() })
@@ -159,6 +165,24 @@ describe('Música', () => {
expect(host.textContent).not.toContain('Saved stations')
})
/* Two situations that are not bugs, and used to look like one: nothing signed in (guest mode
never talks to the api), and an api older than the app — they ship separately, so a deploy that
refreshed the frontend and not the api container is a screen whose every request fails. Both
are a quiet line, and neither makes a request. */
it('tells a guest where the radio comes from, without asking the server', async () => {
useStore.setState({ user: null })
await mount()
expect(host.textContent).toContain('The radio comes from your server, so it needs a profile')
expect(api).not.toHaveBeenCalled()
})
it('says the server is older when it does not offer the radio yet', async () => {
useStore.setState({ config: { features: ['vitals', 'insights'] } })
await mount()
expect(host.textContent).toContain('Your server has not been updated for the radio yet')
expect(api).not.toHaveBeenCalled()
})
it('saving the same link twice does not duplicate the card', async () => {
useStore.setState(s => ({ S: { ...s.S, music: { user: '', playlists: [] } } }))
act(() => { useStore.getState().addPlaylist(item()) })