-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
77 lines (70 loc) · 2.04 KB
/
App.tsx
File metadata and controls
77 lines (70 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { pollsApi } from './api';
import { useQuery } from 'react-query';
import { Link, Route, Switch } from 'wouter';
import { useState } from 'react';
import { Button, Container, Stack, TextField, Typography } from '@mui/material';
import AuthCodeReceiver from './auth/AuthCodeReceiver';
import LoginPage from './auth/LoginPage';
type PollPageProps = {
params: { code: string };
};
function PollPage(props: PollPageProps) {
const { isLoading, isSuccess, isError, data, error } = useQuery(
['poll', props.params.code],
() => pollsApi.pollControllerFindByCode({ code: props.params.code }),
);
return (
<>
<Typography variant='h1'>Poll Page</Typography>
{isLoading && <Typography variant='body1'>Loading ...</Typography>}
{isSuccess && (
<Typography variant='body1'>
The poll: {JSON.stringify(data)}
</Typography>
)}
{isError && (
<Typography variant='body1'>
Could not fetch resource: {JSON.stringify(error)}
</Typography>
)}
</>
);
}
function HomePage() {
const [code, setCode] = useState('');
return (
<>
<Typography variant='h1'>Home</Typography>
<Typography variant='body1'>Please type in the poll code:</Typography>
<Stack spacing={1} marginTop={1}>
<TextField
label='Poll code'
type='text'
variant='outlined'
onChange={(event) => setCode(event.target.value)}
/>
<Link href={`/poll/${code}`}>
<Button variant='contained' type='submit'>
Join Poll
</Button>
</Link>
</Stack>
</>
);
}
function App() {
return (
<Container maxWidth='sm'>
{/* <div>
<Link href="/">SolidPolls</Link>
</div> */}
<Switch>
<Route path='/poll/:code' component={PollPage} />
<Route path='/auth/callback' component={AuthCodeReceiver} />
<Route path='/auth/login' component={LoginPage} />
<Route path='/' component={HomePage} />
</Switch>
</Container>
);
}
export default App;