sonda/web/src/router.tsx
tgiachi 0b3bf8d49f feat: a Radio page, endless play, and the radio of an artist
The Radio page shows the stations Sonda makes by itself, in groups (made for you,
by genre, by decade). A click starts one and the player knows it is a radio: before
the queue runs out it asks the server for other songs of the same station and puts
them at the end (not the ones already queued; a station so small that all its songs
are queued starts them over), one question at a time, never twice within two seconds,
and again after ten when the server cannot answer. Every artist has a Start radio
button. The full-screen player says which station plays.

- Radio item in the menu (Library group), on the Library page and in the phone tab
- player store: radio and appendTracks; useRadioRefill
2026-11-16 12:18:15 +01:00

61 lines
3.7 KiB
TypeScript

import type { ComponentType } from 'react'
import { Navigate, type RouteObject } from 'react-router-dom'
import RouteLoading from '@/components/RouteLoading'
import Shell from '@/components/layout/Shell'
import HomePage from '@/pages/HomePage'
import NotFoundPage from '@/pages/NotFoundPage'
/** A page that is fetched when somebody first opens it, so that the first screen does not carry the admin area. */
const page = (load: () => Promise<{ default: ComponentType }>) => async () => ({ Component: (await load()).default })
export const routes: RouteObject[] = [
{
element: <Shell />,
HydrateFallback: RouteLoading,
children: [
{ path: '/', element: <HomePage /> },
{ path: '/search', lazy: page(() => import('@/pages/SearchPage')) },
{ path: '/discover', lazy: page(() => import('@/pages/DiscoverPage')) },
{ path: '/artists', lazy: page(() => import('@/pages/ArtistsPage')) },
{ path: '/artists/:id', lazy: page(() => import('@/pages/ArtistPage')) },
{ path: '/albums', lazy: page(() => import('@/pages/AlbumsPage')) },
{ path: '/albums/:id', lazy: page(() => import('@/pages/AlbumPage')) },
{ path: '/songs', lazy: page(() => import('@/pages/SongsPage')) },
{ path: '/favorites', lazy: page(() => import('@/pages/FavoritesPage')) },
{ path: '/library', lazy: page(() => import('@/pages/LibraryPage')) },
{ path: '/more', lazy: page(() => import('@/pages/MorePage')) },
{ path: '/friends', lazy: page(() => import('@/pages/FriendsPage')) },
{ path: '/friends/:friend', lazy: page(() => import('@/pages/FriendPage')) },
{ path: '/mixes', lazy: page(() => import('@/pages/MixesPage')) },
{ path: '/radio', lazy: page(() => import('@/pages/RadioPage')) },
{ path: '/mixes/:id', lazy: page(() => import('@/pages/MixPage')) },
{ path: '/playlists', lazy: page(() => import('@/pages/PlaylistsPage')) },
{ path: '/playlists/:id', lazy: page(() => import('@/pages/PlaylistPage')) },
{ path: '/smart-playlists', lazy: page(() => import('@/pages/SmartPlaylistsPage')) },
{ path: '/smart-playlists/new', lazy: page(() => import('@/pages/SmartEditorPage')) },
{ path: '/smart-playlists/suggested/:key', lazy: page(() => import('@/pages/SuggestedSmartPage')) },
{ path: '/smart-playlists/:id', lazy: page(() => import('@/pages/SmartPlaylistPage')) },
{ path: '/smart-playlists/:id/edit', lazy: page(() => import('@/pages/SmartEditorPage')) },
{ path: '/requests', lazy: page(() => import('@/pages/RequestsPage')) },
{ path: '/history', lazy: page(() => import('@/pages/HistoryPage')) },
{ path: '/stats', lazy: page(() => import('@/pages/StatsPage')) },
{ path: '/import', lazy: page(() => import('@/pages/ImportPage')) },
{ path: '/settings', lazy: page(() => import('@/pages/SettingsPage')) },
{
path: '/admin',
lazy: page(() => import('@/pages/admin/AdminLayout')),
children: [
{ index: true, element: <Navigate to="/admin/libraries" replace /> },
{ path: 'libraries', lazy: page(() => import('@/pages/admin/LibrariesPage')) },
{ path: 'users', lazy: page(() => import('@/pages/admin/UsersPage')) },
{ path: 'providers', lazy: page(() => import('@/pages/admin/ProvidersPage')) },
{ path: 'federation', lazy: page(() => import('@/pages/admin/FederationPage')) },
{ path: 'jobs', lazy: page(() => import('@/pages/admin/JobsPage')) },
{ path: 'duplicates', lazy: page(() => import('@/pages/admin/DuplicatesPage')) },
{ path: 'costs', lazy: page(() => import('@/pages/admin/CostsPage')) },
],
},
{ path: '*', element: <NotFoundPage /> },
],
},
]