mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 19:29:51 -04:00
use new API
This commit is contained in:
parent
50c57d9ed4
commit
9880c9f1f9
|
@ -30,8 +30,8 @@ function App() {
|
||||||
<Route component={Groups} path="/groups" />
|
<Route component={Groups} path="/groups" />
|
||||||
<Route component={MyGroups} path="/mygroups" />
|
<Route component={MyGroups} path="/mygroups" />
|
||||||
<Route component={UpdatePool} path="/update_pool" />
|
<Route component={UpdatePool} path="/update_pool" />
|
||||||
<Route component={Group} path="/group/:id" />
|
<Route component={Group} path="/groups/:id" />
|
||||||
<Route component={Pool} path="/pool/:id" />
|
<Route component={Pool} path="/pools/:id" />
|
||||||
<Route component={Profile} path="/profile" />
|
<Route component={Profile} path="/profile" />
|
||||||
<Route component={Home} path="/" />
|
<Route component={Home} path="/" />
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|
|
@ -32,11 +32,11 @@ export async function createSession(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMe(): Promise<Carpool.User> {
|
export async function getMe(): Promise<Carpool.User> {
|
||||||
let result = await makeAPIGetCall('/user', { userID: '@me' });
|
let result = await makeAPIGetCall('/users/@me');
|
||||||
return result.data.data;
|
return result.data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPublicUser(id: string): Promise<Carpool.PublicUser> {
|
export async function getPublicUser(id: string): Promise<Carpool.PublicUser> {
|
||||||
let result = await makeAPIGetCall('/user', { userID: id });
|
let result = await makeAPIGetCall(`/users/${id}`);
|
||||||
return result.data.data;
|
return result.data.data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,9 @@ const useStyles = makeStyles((theme) => ({
|
||||||
const CreateGroup = () => {
|
const CreateGroup = () => {
|
||||||
const [title, setTitle] = useState('No Title');
|
const [title, setTitle] = useState('No Title');
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
useEffect(() => {}, []);
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
console.log({
|
makeAPIPostCall('/groups/', { title });
|
||||||
title: title,
|
|
||||||
});
|
|
||||||
makeAPIPostCall('/group', {
|
|
||||||
title,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -30,7 +30,7 @@ const CreatePool = () => {
|
||||||
const [group, setGroup] = useState('');
|
const [group, setGroup] = useState('');
|
||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
makeAPIPostCall('/pool', {
|
makeAPIPostCall('/pools/', {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
start_time: start,
|
start_time: start,
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default function Group() {
|
||||||
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
|
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/group', { groupID: id }).then((res) => {
|
makeAPIGetCall(`/groups/${id}`).then((res) => {
|
||||||
if ('error' in res.data) {
|
if ('error' in res.data) {
|
||||||
setError(true);
|
setError(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,7 +51,7 @@ export default function Group() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
makeAPIGetCall('/group_pools', { groupID: id }).then((res) => {
|
makeAPIGetCall(`/groups/${id}/pools`).then((res) => {
|
||||||
setPools(res.data.data);
|
setPools(res.data.data);
|
||||||
});
|
});
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
@ -90,7 +90,7 @@ export default function Group() {
|
||||||
{pools.map((pool, index) => {
|
{pools.map((pool, index) => {
|
||||||
return (
|
return (
|
||||||
<Card style={{ margin: '0.5em' }} key={index}>
|
<Card style={{ margin: '0.5em' }} key={index}>
|
||||||
<a href={'/pool/' + pool._id} className="card-title">
|
<a href={'/pools/' + pool._id} className="card-title">
|
||||||
{pool.title}
|
{pool.title}
|
||||||
</a>
|
</a>
|
||||||
<p className="text-left">
|
<p className="text-left">
|
||||||
|
|
|
@ -12,7 +12,7 @@ const Groups = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/groups').then((res) => {
|
makeAPIGetCall('/browse/groups').then((res) => {
|
||||||
if (res.data.data) {
|
if (res.data.data) {
|
||||||
setGroups(res.data.data);
|
setGroups(res.data.data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ const MyGroups = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/groups').then((res) => {
|
makeAPIGetCall('/browse/groups').then((res) => {
|
||||||
if (res.data.data) {
|
if (res.data.data) {
|
||||||
setGroups(res.data.data);
|
setGroups(res.data.data);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ const MyGroups = () => {
|
||||||
className="card card-body text-left"
|
className="card card-body text-left"
|
||||||
style={{ backgroundColor: background }}
|
style={{ backgroundColor: background }}
|
||||||
>
|
>
|
||||||
<a href={'/group/' + group._id} className="card-title">
|
<a href={'/groups/' + group._id} className="card-title">
|
||||||
{group.name}
|
{group.name}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -56,7 +56,7 @@ const MyPools = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/my_pools').then((res) => {
|
makeAPIGetCall('/users/@me/pools').then((res) => {
|
||||||
if (res.data.data) {
|
if (res.data.data) {
|
||||||
setPools(res.data.data);
|
setPools(res.data.data);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ const MyPools = () => {
|
||||||
className="card card-body text-left"
|
className="card card-body text-left"
|
||||||
style={{ backgroundColor: background }}
|
style={{ backgroundColor: background }}
|
||||||
>
|
>
|
||||||
<a href={'/Pool/' + pool.id} className="card-title">
|
<a href={'/pools/' + pool.id} className="card-title">
|
||||||
{pool.pool_title}
|
{pool.pool_title}
|
||||||
</a>
|
</a>
|
||||||
<p className="text-left">
|
<p className="text-left">
|
||||||
|
|
|
@ -77,7 +77,7 @@ export default function Pool() {
|
||||||
const onRegister = useCallback(() => {
|
const onRegister = useCallback(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
let userID = user._id;
|
let userID = user._id;
|
||||||
makeAPIPostCall('/join_pool', { id }).then(() => {
|
makeAPIPostCall(`/pools/${id}/join`).then(() => {
|
||||||
if (pool) {
|
if (pool) {
|
||||||
setPool({
|
setPool({
|
||||||
...pool,
|
...pool,
|
||||||
|
@ -89,7 +89,7 @@ export default function Pool() {
|
||||||
}, [user, id, pool]);
|
}, [user, id, pool]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/pool', { poolID: id }).then((response) => {
|
makeAPIGetCall(`/pools/${id}`).then((response) => {
|
||||||
if (response.data.data) {
|
if (response.data.data) {
|
||||||
setPool(response.data.data);
|
setPool(response.data.data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ const Pools = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/my_pools').then((res) => {
|
makeAPIGetCall(`/users/@me/pools`).then((res) => {
|
||||||
if (res.data.data) {
|
if (res.data.data) {
|
||||||
setPools(res.data.data);
|
setPools(res.data.data);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ const Pools = () => {
|
||||||
className="card card-body text-left"
|
className="card card-body text-left"
|
||||||
style={{ backgroundColor: background }}
|
style={{ backgroundColor: background }}
|
||||||
>
|
>
|
||||||
<a href={'/pool/' + pool._id} className="card-title">
|
<a href={'/pools/' + pool._id} className="card-title">
|
||||||
{pool.title}
|
{pool.title}
|
||||||
</a>
|
</a>
|
||||||
<p className="text-left">
|
<p className="text-left">
|
||||||
|
|
|
@ -25,7 +25,7 @@ const Profile = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/my_pools').then((res) => {
|
makeAPIGetCall('/users/@me/pools').then((res) => {
|
||||||
if (res.data.data) setPools(res.data.data);
|
if (res.data.data) setPools(res.data.data);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -56,7 +56,7 @@ const Profile = () => {
|
||||||
className={classes.root + 'd-inline-flex'}
|
className={classes.root + 'd-inline-flex'}
|
||||||
style={{ margin: '0.5rem' }}
|
style={{ margin: '0.5rem' }}
|
||||||
>
|
>
|
||||||
<CardActionArea href={'/pool/' + pool._id}>
|
<CardActionArea href={'/pools/' + pool._id}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography gutterBottom variant="h5" component="h2">
|
<Typography gutterBottom variant="h5" component="h2">
|
||||||
{pool.title}
|
{pool.title}
|
||||||
|
@ -75,14 +75,14 @@ const Profile = () => {
|
||||||
size="small"
|
size="small"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
let link: string = 'localhost:3000/pool/' + pool._id;
|
let link: string = 'localhost:3000/pools/' + pool._id;
|
||||||
navigator.clipboard.writeText(link);
|
navigator.clipboard.writeText(link);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Share
|
Share
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
href={'/pool/' + pool._id}
|
href={'/pools/' + pool._id}
|
||||||
size="small"
|
size="small"
|
||||||
color="primary"
|
color="primary"
|
||||||
>
|
>
|
||||||
|
|
|
@ -24,12 +24,12 @@ const UpdatePool = () => {
|
||||||
|
|
||||||
const onSubmit: FormEventHandler<HTMLFormElement> = (e) => {
|
const onSubmit: FormEventHandler<HTMLFormElement> = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
makeAPIGetCall('/update_pool').then((res) => {
|
makeAPIGetCall(`/pools/${id}`).then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall('/pool', { poolID: id }).then((res) => {
|
makeAPIGetCall(`/pools/${id}`).then((res) => {
|
||||||
if (res.data.data) setPool(res.data.data);
|
if (res.data.data) setPool(res.data.data);
|
||||||
});
|
});
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user