From f8463676a40656893c2048655e8807099e3adb39 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Mon, 10 Apr 2023 21:57:33 +0200 Subject: add radio app --- apps/Radio/components/List.js | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 apps/Radio/components/List.js (limited to 'apps/Radio/components/List.js') diff --git a/apps/Radio/components/List.js b/apps/Radio/components/List.js new file mode 100644 index 0000000..73e1523 --- /dev/null +++ b/apps/Radio/components/List.js @@ -0,0 +1,48 @@ +import { open } from 'helpers/windowActions' +import appList from 'configs/appList' +import useApps from 'hooks/useApps' +import fetchJson from 'helpers/fetchJson' +import styles from '../styles/Radio.module.scss' + +const play = async (title, station, apps, setApps, enqueue) => { + const streamData = await fetchJson('/api/radio/stream', { + method: 'POST', + body: JSON.stringify({ station }) + }) + + const items = [{ type: 'radio', title, ...streamData }] + + apps && apps.length > 0 && apps.some(a => a && a.name === 'Player') + ? setApps(prev => prev.map(a => a.name === 'Player' ? { ...a, props: { list: { items, enqueue } } } : a)) + : open({ appName: 'Player', ...appList.Player }, setApps, { list: { items, enqueue } }) +} + +const List = ({ results, enqueue }) => { + const { apps, setApps } = useApps() + + return ( +
+
+ {results && results.length === 0 &&
No results
} + {results && results.length > 0 && ( + results.map(({ title, url, logo, genres, locations }) => ( +
play(title, url, apps, setApps, enqueue)}> + title +
+ { title } +
+ {locations.join(', ')} +
+ {genres.map(g => {g})} +
+
+
+
+ )) + )} +
+
+ ) +} + +export default List -- cgit v1.2.3