diff options
author | 2023-04-10 21:57:33 +0200 | |
---|---|---|
committer | 2023-04-10 21:57:33 +0200 | |
commit | f8463676a40656893c2048655e8807099e3adb39 (patch) | |
tree | 9b38927a293e38ec38da2707434786d92327edd0 /apps/Radio/components/List.js | |
parent | f4e00553c4acf44de48af958afc8747128b55562 (diff) | |
download | my_apps-f8463676a40656893c2048655e8807099e3adb39.tar.gz my_apps-f8463676a40656893c2048655e8807099e3adb39.tar.bz2 my_apps-f8463676a40656893c2048655e8807099e3adb39.zip |
add radio app
Diffstat (limited to 'apps/Radio/components/List.js')
-rw-r--r-- | apps/Radio/components/List.js | 48 |
1 files changed, 48 insertions, 0 deletions
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 ( + <div className={styles.list}> + <div> + {results && results.length === 0 && <div>No results</div>} + {results && results.length > 0 && ( + results.map(({ title, url, logo, genres, locations }) => ( + <div key={url} onClick={() => play(title, url, apps, setApps, enqueue)}> + <img width={75} height={75} src={logo} loading="lazy" alt="title" /> + <div> + <span>{ title }</span> + <div> + <span>{locations.join(', ')}</span> + <div> + {genres.map(g => <span>{g}</span>)} + </div> + </div> + </div> + </div> + )) + )} + </div> + </div> + ) +} + +export default List |