mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
improve groups UI
This commit is contained in:
parent
e02589b26d
commit
7a897a142b
|
@ -1,13 +1,10 @@
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import Card from '@material-ui/core/Card';
|
|
||||||
import Typography from '@material-ui/core/Typography';
|
import Typography from '@material-ui/core/Typography';
|
||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { makeAPIGetCall } from '../api/utils';
|
import { makeAPIGetCall } from '../api/utils';
|
||||||
import CreatePool from './CreatePool';
|
import CreatePool from './CreatePool';
|
||||||
|
import Pool from './Pool';
|
||||||
const maybePluralize = (count: number, noun: string, suffix = 's') =>
|
|
||||||
`${count} ${noun}${count !== 1 ? suffix : ''}`;
|
|
||||||
|
|
||||||
const SAMPLE_POOLS: Carpool.Pool[] = [
|
const SAMPLE_POOLS: Carpool.Pool[] = [
|
||||||
{
|
{
|
||||||
|
@ -41,9 +38,17 @@ export default function Group() {
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [group, setGroup] = useState<Carpool.Group>();
|
const [group, setGroup] = useState<Carpool.Group>();
|
||||||
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
|
const [pools, setPools] = useState<Carpool.Pool[]>([]);
|
||||||
const [createPoolVisible, setCreatePoolVisible] = useState(false);
|
const [createPoolVisible, setCreatePoolVisible] = useState(false);
|
||||||
|
|
||||||
|
const fetchPools = useCallback(() => {
|
||||||
|
makeAPIGetCall(`/groups/${id}/pools`).then((res) => {
|
||||||
|
setPools(res.data.data);
|
||||||
|
});
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => fetchPools(), [fetchPools]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall(`/groups/${id}`).then((res) => {
|
makeAPIGetCall(`/groups/${id}`).then((res) => {
|
||||||
if ('error' in res.data) {
|
if ('error' in res.data) {
|
||||||
|
@ -52,10 +57,6 @@ export default function Group() {
|
||||||
setGroup(res.data.data);
|
setGroup(res.data.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
makeAPIGetCall(`/groups/${id}/pools`).then((res) => {
|
|
||||||
setPools(res.data.data);
|
|
||||||
});
|
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -93,19 +94,7 @@ export default function Group() {
|
||||||
{createPoolVisible && <CreatePool groupID={group._id} />}
|
{createPoolVisible && <CreatePool groupID={group._id} />}
|
||||||
</div>
|
</div>
|
||||||
{pools.map((pool, index) => (
|
{pools.map((pool, index) => (
|
||||||
<Card style={{ margin: '0.5rem', padding: '0.5rem' }} key={index}>
|
<Pool pool={pool} triggerUpdate={fetchPools} key={index} />
|
||||||
<a href={'/pools/' + pool._id} className="card-title">
|
|
||||||
{pool.title}
|
|
||||||
</a>
|
|
||||||
<p className="text-left">
|
|
||||||
Capacity: {pool.participant_ids.length} / {pool.capacity}
|
|
||||||
</p>
|
|
||||||
<p className="text-left">Start Time: {pool.start_time}</p>
|
|
||||||
<p className="text-left">End Time: {pool.end_time}</p>
|
|
||||||
<p className="text-warning">
|
|
||||||
{maybePluralize(pool.comments.length, 'comment')}
|
|
||||||
</p>
|
|
||||||
</Card>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,6 +19,11 @@ const useStyles = makeStyles({
|
||||||
textTransform: `uppercase`,
|
textTransform: `uppercase`,
|
||||||
color: `white`,
|
color: `white`,
|
||||||
},
|
},
|
||||||
|
'linkText:hover': {
|
||||||
|
textDecoration: `none`,
|
||||||
|
textTransform: `uppercase`,
|
||||||
|
color: `white`,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const navLinks = [
|
const navLinks = [
|
||||||
{ title: `Profile`, path: `/profile` },
|
{ title: `Profile`, path: `/profile` },
|
||||||
|
@ -28,7 +33,7 @@ const navLinks = [
|
||||||
const Nav = () => {
|
const Nav = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<AppBar position="static" style={{ background: '#40E0D0' }}>
|
<AppBar position="static" style={{ background: '#4287f5' }}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<Container maxWidth="xl" className={classes.navbarDisplayFlex}>
|
<Container maxWidth="xl" className={classes.navbarDisplayFlex}>
|
||||||
<IconButton href="/" edge="start" color="inherit" aria-label="home">
|
<IconButton href="/" edge="start" color="inherit" aria-label="home">
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { useState, useEffect, useCallback, useRef, useContext } from 'react';
|
import { useState, useCallback, useRef, useContext } from 'react';
|
||||||
import { useParams } from 'react-router';
|
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import Card from '@material-ui/core/Card';
|
import Card from '@material-ui/core/Card';
|
||||||
import Textarea from '@material-ui/core/TextareaAutosize';
|
import Textarea from '@material-ui/core/TextareaAutosize';
|
||||||
import Typography from '@material-ui/core/Typography';
|
import Typography from '@material-ui/core/Typography';
|
||||||
import Comment from './Comment';
|
import Comment from './Comment';
|
||||||
import { makeAPIGetCall, makeAPIPostCall } from '../api/utils';
|
import { makeAPIPostCall } from '../api/utils';
|
||||||
import AuthenticationContext from './AuthenticationContext';
|
import AuthenticationContext from './AuthenticationContext';
|
||||||
import PoolMap from './PoolMap';
|
import PoolMap from './PoolMap';
|
||||||
|
|
||||||
|
@ -35,9 +34,13 @@ const SAMPLE_POOL = {
|
||||||
type: 'offer',
|
type: 'offer',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Pool() {
|
export default function Pool({
|
||||||
const id = useParams<{ id: string }>().id;
|
pool,
|
||||||
const [pool, setPool] = useState<Carpool.Pool>();
|
triggerUpdate,
|
||||||
|
}: {
|
||||||
|
pool: Carpool.Pool;
|
||||||
|
triggerUpdate: Function;
|
||||||
|
}) {
|
||||||
const { user } = useContext(AuthenticationContext);
|
const { user } = useContext(AuthenticationContext);
|
||||||
|
|
||||||
const commentTextareaRef = useRef<HTMLTextAreaElement>(null);
|
const commentTextareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
@ -76,41 +79,12 @@ export default function Pool() {
|
||||||
);
|
);
|
||||||
|
|
||||||
const onRegister = useCallback(() => {
|
const onRegister = useCallback(() => {
|
||||||
if (user) {
|
makeAPIPostCall(`/pools/${pool._id}/join`).then(() => triggerUpdate());
|
||||||
let userID = user._id;
|
}, [pool._id, triggerUpdate]);
|
||||||
makeAPIPostCall(`/pools/${id}/join`).then(() => {
|
|
||||||
if (pool) {
|
|
||||||
setPool({
|
|
||||||
...pool,
|
|
||||||
participant_ids: [...pool.participant_ids, userID],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [user, id, pool]);
|
|
||||||
|
|
||||||
const onUnregister = useCallback(() => {
|
const onUnregister = useCallback(() => {
|
||||||
if (user) {
|
makeAPIPostCall(`/pools/${pool._id}/leave`).then(() => triggerUpdate());
|
||||||
makeAPIPostCall(`/pools/${id}/leave`).then(() => {
|
}, [pool._id, triggerUpdate]);
|
||||||
if (pool) {
|
|
||||||
let participants: string[] = [];
|
|
||||||
pool.participant_ids.forEach((e) => participants.push(e));
|
|
||||||
setPool({
|
|
||||||
...pool,
|
|
||||||
participant_ids: [...participants],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [user, id, pool]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
makeAPIGetCall(`/pools/${id}`).then((response) => {
|
|
||||||
if (response.data.data) {
|
|
||||||
setPool(response.data.data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [id, pool]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card style={{ margin: '3rem auto', padding: '1rem 1rem', width: '50%' }}>
|
<Card style={{ margin: '3rem auto', padding: '1rem 1rem', width: '50%' }}>
|
||||||
|
|
21
src/components/PoolPage.tsx
Normal file
21
src/components/PoolPage.tsx
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { makeAPIGetCall } from '../api/utils';
|
||||||
|
import Pool from './Pool';
|
||||||
|
|
||||||
|
export default function PoolPage() {
|
||||||
|
const id = useParams<{ id: string }>().id;
|
||||||
|
const [pool, setPool] = useState<Carpool.Pool>();
|
||||||
|
|
||||||
|
const fetchData = useCallback(() => {
|
||||||
|
makeAPIGetCall(`/pools/${id}`).then((response) => {
|
||||||
|
if (response.data.data) {
|
||||||
|
setPool(response.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => fetchData(), [fetchData]);
|
||||||
|
|
||||||
|
return pool ? <Pool pool={pool} triggerUpdate={fetchData} /> : null;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user