mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 19:29:51 -04:00
add group page
This commit is contained in:
parent
db955f44b2
commit
8d668ea489
|
@ -1,52 +1,20 @@
|
||||||
import { useEffect, useState } from 'react';
|
import WheelShare from './WheelShare';
|
||||||
import EventStream from './EventStream';
|
import { BrowserRouter, Route, Switch } from 'react-router-dom';
|
||||||
import { IGroup } from './Group';
|
import { lazy, Suspense } from 'react';
|
||||||
import GroupCreator from './GroupCreator';
|
|
||||||
import GroupList from './GroupList';
|
const Group = lazy(() => import('./Group'));
|
||||||
import UIPrimaryTitle from './UIPrimaryTitle';
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [groups, setGroups] = useState<IGroup[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetch('http://localhost:5000/api/groups')
|
|
||||||
.then((res) => res.json())
|
|
||||||
.then(setGroups);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div style={{ padding: '1rem' }}>
|
||||||
style={{
|
<BrowserRouter>
|
||||||
display: 'flex',
|
<Switch>
|
||||||
flexDirection: 'column',
|
<Route path="/" exact component={WheelShare} />
|
||||||
alignItems: 'center',
|
<Suspense fallback={null}>
|
||||||
width: '30rem',
|
<Route path="/groups/:id" component={Group} />
|
||||||
maxWidth: '30rem',
|
</Suspense>
|
||||||
marginLeft: 'auto',
|
</Switch>
|
||||||
marginRight: 'auto',
|
</BrowserRouter>
|
||||||
}}
|
|
||||||
>
|
|
||||||
<UIPrimaryTitle>WheelShare</UIPrimaryTitle>
|
|
||||||
<GroupCreator />
|
|
||||||
<h1>Groups</h1>
|
|
||||||
<GroupList groups={groups} />
|
|
||||||
<h1>Events</h1>
|
|
||||||
<EventStream
|
|
||||||
events={[
|
|
||||||
{
|
|
||||||
time: '11:00 AM to 2:45 PM',
|
|
||||||
title: 'TJ Track Regional Meet',
|
|
||||||
group: 'TJHSST Track and Field',
|
|
||||||
location: 'Ashburn, Virginia',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
time: '5:00 PM to 8:00 PM',
|
|
||||||
title: 'End of Year Party',
|
|
||||||
group: 'TJHSST 2022',
|
|
||||||
location: 'Dulles, Virginia',
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,41 @@
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
import { post } from './api';
|
||||||
|
import { IGroup } from './Group';
|
||||||
import UIButton from './UIButton';
|
import UIButton from './UIButton';
|
||||||
import UIDatetimeInput from './UIDatetimeInput';
|
import UIDatetimeInput from './UIDatetimeInput';
|
||||||
import UIPlacesAutocomplete from './UIPlacesAutocomplete';
|
import UIPlacesAutocomplete from './UIPlacesAutocomplete';
|
||||||
import UISecondaryBox from './UISecondaryBox';
|
import UISecondaryBox from './UISecondaryBox';
|
||||||
import UITextInput from './UITextInput';
|
import UITextInput from './UITextInput';
|
||||||
|
|
||||||
export default function EventCreator() {
|
export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const [startTime, setStartTime] = useState<Date | null>(null);
|
const [startTime, setStartTime] = useState<Date | null>(null);
|
||||||
const [endTime, setEndTime] = useState<Date | null>(null);
|
const [endTime, setEndTime] = useState<Date | null>(null);
|
||||||
const [placeId, setPlaceId] = useState<string | null>(null);
|
const [placeId, setPlaceId] = useState<string | null>(null);
|
||||||
const [groupId, setGroupId] = useState('');
|
|
||||||
|
|
||||||
const createEvent = useCallback(() => {
|
const createEvent = useCallback(() => {
|
||||||
fetch('http://localhost:5000/api/events', {
|
post('/events', {
|
||||||
method: 'post',
|
|
||||||
body: JSON.stringify({
|
|
||||||
name,
|
name,
|
||||||
startTime,
|
startTime,
|
||||||
endTime,
|
endTime,
|
||||||
groupId,
|
groupId: group.id,
|
||||||
placeId,
|
placeId,
|
||||||
}),
|
})
|
||||||
headers: {
|
.then((response) => response.json())
|
||||||
'Content-Type': 'application/json',
|
.then(({ id }) => {
|
||||||
},
|
window.location.href = `/groups/${id}`;
|
||||||
});
|
});
|
||||||
}, [name, startTime, endTime, groupId, placeId]);
|
}, [name, startTime, endTime, group.id, placeId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}>
|
<UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}>
|
||||||
<h1 style={{ textAlign: 'center' }}>Create Event</h1>
|
<h1 style={{ textAlign: 'center', marginBottom: '0.5rem' }}>
|
||||||
|
Create Event
|
||||||
|
</h1>
|
||||||
|
<h3 style={{ textAlign: 'center', marginTop: '0.5rem' }}>{group.name}</h3>
|
||||||
Name
|
Name
|
||||||
<UITextInput value={name} onChangeText={setName} />
|
<UITextInput value={name} onChangeText={setName} />
|
||||||
<br />
|
<br />
|
||||||
Group
|
|
||||||
<UITextInput value={groupId} onChangeText={setGroupId} />
|
|
||||||
<br />
|
|
||||||
Start time
|
Start time
|
||||||
<UIDatetimeInput onChangedDate={setStartTime} />
|
<UIDatetimeInput onChangedDate={setStartTime} />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useParams } from 'react-router';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import { IEvent } from './Event';
|
import { IEvent } from './Event';
|
||||||
import EventCreator from './EventCreator';
|
import EventCreator from './EventCreator';
|
||||||
import EventStream from './EventStream';
|
import EventStream from './EventStream';
|
||||||
|
@ -8,13 +11,51 @@ export type IGroup = {
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Group({ events, name }: IGroup) {
|
export default function Group() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [group, setGroup] = useState<IGroup | null>(null);
|
||||||
|
const [events, setEvents] = useState<IEvent[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true);
|
||||||
|
fetch('http://localhost:5000/api/groups/' + id)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(setGroup)
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
|
||||||
|
fetch('http://localhost:5000/api/groups/' + id + '/events')
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(setEvents);
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
if (!group && !loading) {
|
||||||
return (
|
return (
|
||||||
<div style={{ textAlign: 'center', width: '100%' }}>
|
<div style={{ textAlign: 'center' }}>
|
||||||
<EventCreator />
|
<h1>Group Not Found</h1>
|
||||||
|
<Link to="/">Home</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!group) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name } = group;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
maxWidth: '30rem',
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
}}
|
||||||
|
>
|
||||||
<h1>{name}</h1>
|
<h1>{name}</h1>
|
||||||
|
<EventCreator group={group} />
|
||||||
<EventStream events={events} />
|
<EventStream events={events} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
|
import { post } from './api';
|
||||||
import UIButton from './UIButton';
|
import UIButton from './UIButton';
|
||||||
import UISecondaryBox from './UISecondaryBox';
|
import UISecondaryBox from './UISecondaryBox';
|
||||||
import UITextInput from './UITextInput';
|
import UITextInput from './UITextInput';
|
||||||
|
@ -6,14 +7,8 @@ import UITextInput from './UITextInput';
|
||||||
export default function GroupCreator() {
|
export default function GroupCreator() {
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const createGroup = useCallback(() => {
|
const createGroup = useCallback(() => {
|
||||||
fetch('http://localhost:5000/api/groups', {
|
post('/groups', {
|
||||||
method: 'post',
|
|
||||||
body: JSON.stringify({
|
|
||||||
name,
|
name,
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}, [name]);
|
}, [name]);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,17 @@ import UISecondaryBox from './UISecondaryBox';
|
||||||
function GroupListItem({ group }: { group: IGroup }) {
|
function GroupListItem({ group }: { group: IGroup }) {
|
||||||
return (
|
return (
|
||||||
<UISecondaryBox>
|
<UISecondaryBox>
|
||||||
<h2 style={{ textAlign: 'center' }}>{group.name}</h2>
|
<h2
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
window.location.href = `/groups/${group.id}`;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{group.name}
|
||||||
|
</h2>
|
||||||
</UISecondaryBox>
|
</UISecondaryBox>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
52
src/components/NewUI/WheelShare.tsx
Normal file
52
src/components/NewUI/WheelShare.tsx
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import EventStream from './EventStream';
|
||||||
|
import { IGroup } from './Group';
|
||||||
|
import GroupCreator from './GroupCreator';
|
||||||
|
import GroupList from './GroupList';
|
||||||
|
import UIPrimaryTitle from './UIPrimaryTitle';
|
||||||
|
|
||||||
|
export default function WheelShare() {
|
||||||
|
const [groups, setGroups] = useState<IGroup[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch('http://localhost:5000/api/groups')
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then(setGroups);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
width: '30rem',
|
||||||
|
maxWidth: '30rem',
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<UIPrimaryTitle>WheelShare</UIPrimaryTitle>
|
||||||
|
<GroupCreator />
|
||||||
|
<h1>Groups</h1>
|
||||||
|
<GroupList groups={groups} />
|
||||||
|
<h1>Events</h1>
|
||||||
|
<EventStream
|
||||||
|
events={[
|
||||||
|
{
|
||||||
|
time: '11:00 AM to 2:45 PM',
|
||||||
|
title: 'TJ Track Regional Meet',
|
||||||
|
group: 'TJHSST Track and Field',
|
||||||
|
location: 'Ashburn, Virginia',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
time: '5:00 PM to 8:00 PM',
|
||||||
|
title: 'End of Year Party',
|
||||||
|
group: 'TJHSST 2022',
|
||||||
|
location: 'Dulles, Virginia',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
9
src/components/NewUI/api.ts
Normal file
9
src/components/NewUI/api.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export function post(path: string, data: any) {
|
||||||
|
return fetch('http://localhost:5000/api' + path, {
|
||||||
|
method: 'post',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user