import { Fragment, useEffect } from 'react'; import React, { useMemo, useState } from 'react'; import { isAudioFile, readDir, dir, playFile } from './files.mjs'; export function FilesTab() { const [path, setPath] = useState([]); useEffect(() => { let init = false; readDir('', { dir, recursive: true }) .then((children) => setPath([{ name: '~/music', children }])) .catch((err) => { console.log('error loadin files', err); }); return () => { init = true; }; }, []); const current = useMemo(() => path[path.length - 1], [path]); const subpath = useMemo( () => path .slice(1) .map((p) => p.name) .join('/'), [path], ); const folders = useMemo(() => current?.children.filter((e) => !!e.children), [current]); const files = useMemo(() => current?.children.filter((e) => !e.children && isAudioFile(e.name)), [current]); const select = (e) => setPath((p) => p.concat([e])); return (