72 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-12-24 17:19:49 +03:30
import React, { useState } from 'react';
2020-12-24 03:21:18 +03:30
import {
BrowserRouter as Router,
Switch,
Route,
2020-12-24 17:19:49 +03:30
} from 'react-router-dom';
2020-12-24 15:02:03 +03:30
import Button from '@material-ui/core/Button';
2020-12-24 17:19:49 +03:30
import NavBar from './components/NavBar';
import ExtensionCard from './components/ExtensionCard';
2020-12-25 06:36:34 +03:30
import SourceCard from './components/SourceCard';
2020-12-24 03:21:18 +03:30
function Extensions() {
let mapped;
2020-12-24 16:50:50 +01:00
const [extensions, setExtensions] = useState<IExtension[]>([]);
2020-12-24 03:21:18 +03:30
if (extensions.length === 0) {
mapped = <h3>wait</h3>;
2020-12-24 17:19:49 +03:30
fetch('http://127.0.0.1:4567/api/v1/extensions')
.then((response) => response.json())
.then((data) => setExtensions(data));
2020-12-24 03:21:18 +03:30
} else {
2020-12-24 16:50:50 +01:00
mapped = extensions.map((it) => <ExtensionCard extension={it} />);
2020-12-24 03:21:18 +03:30
}
return <h2>{mapped}</h2>;
}
2020-12-25 06:36:34 +03:30
function Sources() {
let mapped;
const [sources, setSources] = useState<ISource[]>([]);
if (sources.length === 0) {
mapped = <h3>wait</h3>;
fetch('http://127.0.0.1:4567/api/v1/sources')
.then((response) => response.json())
.then((data) => setSources(data));
} else {
mapped = sources.map((it) => <SourceCard source={it} />);
}
return <h2>{mapped}</h2>;
}
2020-12-24 03:21:18 +03:30
function Home() {
2020-12-24 15:02:03 +03:30
return (
<Button variant="contained" color="primary">
Hello World
</Button>
2020-12-24 17:19:49 +03:30
);
}
2020-12-24 16:50:50 +01:00
export default function App() {
return (
<Router>
{/* <TemporaryDrawer/> */}
<NavBar />
<Switch>
<Route path="/extensions">
<Extensions />
</Route>
2020-12-25 06:36:34 +03:30
<Route path="/sources">
<Sources />
2020-12-24 16:50:50 +01:00
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
);
}