better messages, axios client

This commit is contained in:
Aria Moradi
2021-03-07 16:27:13 +03:30
parent 954084bd82
commit 7157e07328
7 changed files with 100 additions and 53 deletions

View File

@@ -10,15 +10,17 @@ export default function Sources() {
const { setTitle } = useContext(NavBarTitle);
setTitle('Sources');
const [sources, setSources] = useState<ISource[]>([]);
const [fetched, setFetched] = useState<boolean>(false);
useEffect(() => {
fetch('http://127.0.0.1:4567/api/v1/source/list')
.then((response) => response.json())
.then((data) => setSources(data));
.then((data) => { setSources(data); setFetched(true); });
}, []);
if (sources.length === 0) {
return (<h3>wait</h3>);
if (fetched) return (<h3>No sources found. Install Some Extensions first.</h3>);
return (<h3>loading...</h3>);
}
return <>{sources.map((it) => <SourceCard source={it} />)}</>;
}