59 lines
1.3 KiB
JavaScript
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-24 03:21:18 +03:30
export default function App() {
return (
<Router>
2020-12-24 17:19:49 +03:30
{/* <TemporaryDrawer/> */}
<NavBar />
2020-12-24 03:21:18 +03:30
2020-12-24 15:02:03 +03:30
<Switch>
<Route path="/extensions">
2020-12-24 17:19:49 +03:30
<Extensions />
2020-12-24 15:02:03 +03:30
</Route>
<Route path="/users">
2020-12-24 17:19:49 +03:30
<Users />
2020-12-24 15:02:03 +03:30
</Route>
<Route path="/">
2020-12-24 17:19:49 +03:30
<Home />
2020-12-24 15:02:03 +03:30
</Route>
</Switch>
2020-12-24 03:21:18 +03:30
</Router>
);
}
function Extensions() {
let mapped;
2020-12-24 17:19:49 +03:30
const [extensions, setExtensions] = useState([]);
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 17:19:49 +03:30
mapped = extensions.map((it) => <ExtensionCard {...it} />);
2020-12-24 03:21:18 +03:30
}
return <h2>{mapped}</h2>;
}
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 03:21:18 +03:30
function Users() {
return <h2>Users</h2>;
}