improve pool ui

This commit is contained in:
Michael Fatemi 2021-04-10 17:34:43 -04:00
parent 8f11ed7947
commit 7b8452f84f
3 changed files with 74 additions and 68 deletions

2
.env
View File

@ -1 +1 @@
REACT_APP_API_ENDPOINT=http://localhost:8080/api REACT_APP_API_ENDPOINT=http://localhost:5000/api

View File

@ -0,0 +1,13 @@
import Card from '@material-ui/core/Card';
import Typography from '@material-ui/core/Typography';
export default function Comment({ comment }: { comment: Carpool.Comment }) {
return (
<Card style={{ display: 'flex', flexDirection: 'column', padding: '1rem' }}>
<Typography variant="subtitle2">
<b>Comment by {comment.author_id}</b>
</Typography>
<Typography variant="body2">{comment.body}</Typography>
</Card>
);
}

View File

@ -1,19 +1,37 @@
import { useState, useEffect, FormEventHandler, useCallback } from 'react'; import { useState, useEffect, FormEventHandler, useCallback } from 'react';
import { useParams } from 'react-router'; import { useParams } from 'react-router';
import Button from '@material-ui/core/Button';
import Card from '@material-ui/core/Card';
import Textarea from '@material-ui/core/TextareaAutosize';
import Typography from '@material-ui/core/Typography';
import Comment from './Comment';
const Pool = () => { export default function Pool({ registered = false }: { registered?: boolean }) {
const id = useParams<{ id: string }>().id; const id = useParams<{ id: string }>().id;
const [state, setState] = useState({ const [pool, setPool] = useState<Carpool.Pool>({
id: 1, id: '123',
pool_title: 'TJ Carpool', title: 'TJ Carpool',
pool_text: 'Carpool from TJ track to homes', description: 'Carpool from TJ track to homes',
start_time: '4/10/2021 3:00 PM', start_time: '4/10/2021 3:00 PM',
end_time: '4/10/2021 4:00 PM', end_time: '4/10/2021 4:00 PM',
capacity: 2, capacity: 2,
participants: [], participant_ids: [],
comments: ['What is the covid vaccination status of all the participants?'], comments: [
{
author_id: 'myfatemi04',
id: '1234',
body: "what's the vaccination status of everyone?",
},
],
driver_id: 'None',
create_time: '1234',
update_time: '1234',
group_id: 'tj',
status: 'pending',
direction: 'dropoff',
author_id: 'michael',
type: 'offer',
}); });
const [registered, setRegistered] = useState(false);
const onComment = useCallback<FormEventHandler<HTMLFormElement>>((e) => { const onComment = useCallback<FormEventHandler<HTMLFormElement>>((e) => {
e.preventDefault(); e.preventDefault();
@ -29,70 +47,45 @@ const Pool = () => {
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
if (data !== undefined) { if (data !== undefined) {
setState(data); setPool(data);
} }
}); });
}, [id]); }, [id]);
return ( return (
<div className="bg-dark" style={{ minHeight: '100vh' }}> <Card style={{ margin: '3rem auto', padding: '1rem 1rem', width: '50%' }}>
<h1 <Typography variant="h2" align="center">
style={{ backgroundColor: '#F1EAE8', fontFamily: 'Impact' }} {pool.title}
className="d-flex justify-content-center p-4" </Typography>
<Typography variant="subtitle1">
<b>Capacity</b>: {pool.participant_ids.length} / {pool.capacity}
</Typography>
<Typography variant="subtitle1">
<b>Start Time</b>: {pool.start_time}
</Typography>
<Typography variant="subtitle1">
<b>End Time</b>: {pool.end_time}
</Typography>
<Typography variant="body1">{pool.description}</Typography>
<Button
variant="contained"
color="primary"
style={{ marginTop: '0.5rem' }}
> >
Pool {id} {registered ? 'Unregister' : 'Register'}
</h1> </Button>
<div className="container " style={{ fontFamily: 'Courier New' }}> <hr />
<div className="card card-body " style={{ backgroundColor: '#F1EAE8' }}> <Textarea
<h1 className="card-title">{state.pool_title}</h1> cols={80}
<p className="text-left"> placeholder="Post a comment..."
Capacity: {state.participants.length} / {state.capacity} style={{ margin: '0.5rem 0rem' }}
</p> />
<p className="text-left">Start Time: {state.start_time}</p> <Button variant="contained">Post Comment</Button>
<p className="text-left">End Time: {state.end_time}</p> <div style={{ display: 'flex', flexDirection: 'column' }}>
<p className="text-left">{state.pool_text}</p> {pool.comments.map((comment) => (
<form <Comment comment={comment} key={comment.id} />
action={'register_pool/' + id} ))}
method="POST"
className="text-left"
>
<input
type="submit"
value={!registered ? 'Register' : 'Unregister'}
className={
'text-left btn btn-' + (!registered ? 'success' : 'danger')
}
/>
</form>
</div>
<form onSubmit={onComment}>
<div id="form-group" className="text-left">
<textarea
className="form-control"
id="comment"
placeholder="Enter comment here..."
/>
<input className="btn btn-primary" type="submit" value="Submit" />
</div>
<br />
</form>
<div className="text-left">
<h4 className="text-white">Comments:</h4>
{state.comments.map((comment) => {
return (
<div
className="card card-body"
style={{ backgroundColor: '#D6D1D0' }}
>
<p className="card-text">{comment}</p>
</div>
);
})}
</div>
</div> </div>
</div> </Card>
); );
}; }
export default Pool;