import { exists, readTextFile, writeTextFile } from "@tauri-apps/api/fs" import { Navs, useNavigator } from "./hooks/useNavigator" import { appDataDir } from "@tauri-apps/api/path" import { useEffect, useModel, useRef, useState } from "kaioken" interface Station { url: string avatar: string title: string } export function App() { const { nav, setNavitation } = useNavigator() const [stations, setStations] = useState(null) const [titleRef, title,] = useModel('') const [streamRef, streamUrl,] = useModel('') const [avatarRef, avatarUrl,] = useModel('') const [selectedStation, setSelectedStation] = useState(null) const appDataDirRef = useRef(null) //testforcommit useEffect(() => { appDataDir() .then(async (res) => { const path = `${res}/stations.json` if (await exists(path)) { console.log("file exists: ", path); const jsonString = await readTextFile(path) const json = JSON.parse(jsonString) as Station[] console.log(json) setStations(json) appDataDirRef.current = path return } console.error("File does not exist... creating") writeTextFile(path, "[]", { append: false }) }) .catch(err => console.error(err)) }, []) function _handleStationAdd() { console.log({ title, streamUrl, avatarUrl }) const data: Station = { url: streamUrl, avatar: avatarUrl, title: title } setStations(prev => { const newStations = [...(prev ?? []), data] // write file writeTextFile(appDataDirRef.current!, JSON.stringify(newStations)) return newStations }) console.log("Added station: ", data) setNavitation(Navs.MAIN) } function _handleStationClick(station: Station) { return function() { setSelectedStation(station) setNavitation(Navs.PLAYER) } } if (nav === Navs.MAIN) { if (!stations?.length) { return (

No Stations Added

) } return (
{stations.map((s) => (
))} ) } if (nav === Navs.ADD) { return (
) } function _handlePlayerBackClick() { setNavitation(Navs.MAIN) setSelectedStation(null) } if (nav === Navs.PLAYER) { return (
{/**/} {selectedStation?.title} {/**/}

{selectedStation?.title}

{/**/}

Live Radio


) } return (
Not a navigation
) } //
// //
// //

{selectedStation?.title}

//

Live

//
// {/* progress bar */} //
// //
// {/* play pause button */} //
//
//
// // // //{/**/} //
// // // //
// {/**/} //
//
//
// {/**/} //
// 1:57 // 3:53 //