mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-18 18:10:16 -04:00
25 lines
664 B
TypeScript
25 lines
664 B
TypeScript
import { useEffect } from 'react';
|
|
import { getActiveEvents } from '../api';
|
|
import EventStream from '../EventStream';
|
|
import { IEvent } from '../types';
|
|
import useImmutable from '../useImmutable';
|
|
|
|
export default function ActiveEvents() {
|
|
const [events, setEvents] = useImmutable<IEvent[]>([]);
|
|
|
|
const hasEvents = events.length > 0;
|
|
|
|
useEffect(() => {
|
|
if (!hasEvents) {
|
|
getActiveEvents().then(setEvents).catch(console.error); // TODO error handling
|
|
}
|
|
}, [hasEvents, setEvents]);
|
|
|
|
return (
|
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
<h1 style={{ textAlign: 'center' }}>Events</h1>
|
|
<EventStream events={events} />
|
|
</div>
|
|
);
|
|
}
|