mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-16 00:50:18 -04:00
active carpools page
This commit is contained in:
parent
7acfa610cb
commit
0797c531e5
35
src/components/ActiveCarpools/ActiveCarpools.tsx
Normal file
35
src/components/ActiveCarpools/ActiveCarpools.tsx
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { getActiveCarpools } from '../api';
|
||||||
|
import { ICarpool } from '../types';
|
||||||
|
import UISecondaryBox from '../UI/UISecondaryBox';
|
||||||
|
import UISecondaryHeader from '../UI/UISecondaryHeader';
|
||||||
|
|
||||||
|
function ActiveCarpoolListItem({ carpool }: { carpool: ICarpool }) {
|
||||||
|
return (
|
||||||
|
<UISecondaryBox>
|
||||||
|
<UISecondaryHeader>
|
||||||
|
<a href={'/carpools/' + carpool.id}>{carpool.name}</a>
|
||||||
|
</UISecondaryHeader>
|
||||||
|
</UISecondaryBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ActiveCarpools() {
|
||||||
|
const [activeCarpools, setActiveCarpools] = useState<ICarpool[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getActiveCarpools().then(setActiveCarpools);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>Carpools</h1>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>
|
||||||
|
{activeCarpools.map((carpool) => (
|
||||||
|
<ActiveCarpoolListItem carpool={carpool} key={carpool.id} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { getEvents } from './api';
|
import { getActiveEvents } from '../api';
|
||||||
import { IEvent } from './types';
|
import EventStream from '../EventStream';
|
||||||
import EventStream from './EventStream';
|
import { IEvent } from '../types';
|
||||||
import useImmutable from './useImmutable';
|
import useImmutable from '../useImmutable';
|
||||||
|
|
||||||
export default function Events() {
|
export default function ActiveEvents() {
|
||||||
const [events, setEvents] = useImmutable<IEvent[]>([]);
|
const [events, setEvents] = useImmutable<IEvent[]>([]);
|
||||||
|
|
||||||
const hasEvents = events.length > 0;
|
const hasEvents = events.length > 0;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasEvents) {
|
if (!hasEvents) {
|
||||||
getEvents().then(setEvents);
|
getActiveEvents().then(setEvents);
|
||||||
}
|
}
|
||||||
}, [hasEvents, setEvents]);
|
}, [hasEvents, setEvents]);
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { useCallback, useContext, useMemo, useState } from 'react';
|
import { useCallback, useContext, useState } from 'react';
|
||||||
import { lightgrey } from '../../lib/colors';
|
import { lightgrey } from '../../lib/colors';
|
||||||
import { createCarpool } from '../api';
|
import { createCarpool } from '../api';
|
||||||
import { useMe } from '../hooks';
|
import { useMe } from '../hooks';
|
||||||
import UIButton from '../UI/UIButton';
|
import UIButton from '../UI/UIButton';
|
||||||
import UILink from '../UI/UILink';
|
import UILink from '../UI/UILink';
|
||||||
import EventContext from './EventContext';
|
import EventContext from './EventContext';
|
||||||
|
import { useMyCarpool } from './EventHooks';
|
||||||
|
|
||||||
type CreationStatus = null | 'pending' | 'completed' | 'errored';
|
type CreationStatus = null | 'pending' | 'completed' | 'errored';
|
||||||
|
|
||||||
|
@ -15,13 +16,7 @@ export default function EventCarpoolCreateButton() {
|
||||||
const [createdCarpoolId, setCreatedCarpoolId] = useState<null | number>(null);
|
const [createdCarpoolId, setCreatedCarpoolId] = useState<null | number>(null);
|
||||||
|
|
||||||
const me = useMe()!;
|
const me = useMe()!;
|
||||||
const myCarpool = useMemo(
|
const myCarpool = useMyCarpool();
|
||||||
() =>
|
|
||||||
event.carpools.find((carpool) =>
|
|
||||||
carpool.members.some((member) => member.id === me.id)
|
|
||||||
),
|
|
||||||
[event.carpools, me.id]
|
|
||||||
);
|
|
||||||
|
|
||||||
const createCarpoolCallback = useCallback(async () => {
|
const createCarpoolCallback = useCallback(async () => {
|
||||||
setCreationStatus('pending');
|
setCreationStatus('pending');
|
||||||
|
|
|
@ -1,14 +1,39 @@
|
||||||
import { useContext, useMemo } from 'react';
|
import { useContext, useDebugValue, useMemo } from 'react';
|
||||||
import { useMe } from '../hooks';
|
import { useMe } from '../hooks';
|
||||||
import EventContext from './EventContext';
|
import EventContext from './EventContext';
|
||||||
|
|
||||||
export function useSignups() {
|
export function useSignups() {
|
||||||
return useContext(EventContext).event.signups;
|
const signups = useContext(EventContext).event.signups;
|
||||||
|
|
||||||
|
useDebugValue(signups);
|
||||||
|
|
||||||
|
return signups;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMySignup() {
|
export function useMySignup() {
|
||||||
const signups = useSignups();
|
const signups = useSignups();
|
||||||
const me = useMe()!;
|
const me = useMe()!;
|
||||||
|
|
||||||
return useMemo(() => signups[me.id] ?? null, [signups, me.id]);
|
const signup = useMemo(() => signups[me.id] ?? null, [signups, me.id]);
|
||||||
|
|
||||||
|
useDebugValue(signup);
|
||||||
|
|
||||||
|
return signup;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useMyCarpool() {
|
||||||
|
const me = useMe()!;
|
||||||
|
const { event } = useContext(EventContext);
|
||||||
|
|
||||||
|
const carpool = useMemo(
|
||||||
|
() =>
|
||||||
|
event.carpools.find((carpool) =>
|
||||||
|
carpool.members.some((member) => member.id === me.id)
|
||||||
|
),
|
||||||
|
[event.carpools, me.id]
|
||||||
|
);
|
||||||
|
|
||||||
|
useDebugValue(carpool);
|
||||||
|
|
||||||
|
return carpool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Events from './Events';
|
import ActiveCarpools from './ActiveCarpools/ActiveCarpools';
|
||||||
|
import ActiveEvents from './ActiveEvents/Events';
|
||||||
import Groups from './Groups/Groups';
|
import Groups from './Groups/Groups';
|
||||||
import Header from './Header/Header';
|
import Header from './Header/Header';
|
||||||
|
|
||||||
|
@ -8,7 +9,8 @@ export default function WheelShare() {
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<Groups />
|
<Groups />
|
||||||
<Events />
|
<ActiveCarpools />
|
||||||
|
<ActiveEvents />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,3 +218,11 @@ export async function cancelCarpoolRequest(carpoolId: number) {
|
||||||
export async function getSentRequestsAndInvites() {
|
export async function getSentRequestsAndInvites() {
|
||||||
return (await get('/users/@me/sent_requests_and_invites')) as IInvitation[];
|
return (await get('/users/@me/sent_requests_and_invites')) as IInvitation[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getActiveEvents() {
|
||||||
|
return (await get('/users/@me/active_events')) as IEvent[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getActiveCarpools() {
|
||||||
|
return (await get('/users/@me/active_carpools')) as ICarpool[];
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user