Skip to content

Commit

Permalink
Made Events update in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
rishit-singh committed Dec 30, 2023
1 parent 5708bdd commit de806d9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions frontend/src/app/events/EventsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Events from "./Events";
import { fetchEventsAsync } from "../thunks/EventThunks";
import { AppDispatch } from "../stores/store";
import { CalendarEvent, SetCalendarEvents, selectEvents } from "../slices/eventSlice";
import { Timer } from "../hacks/Timer";

export default function EventsPage()
{
Expand All @@ -15,15 +16,16 @@ export default function EventsPage()
mainDispatch(SetCurrentPage("/events"));

useEffect(() => {
(async () => {
if (events.length < 1)
{
const fetchedEvents: CalendarEvent[] = (await mainDispatch(fetchEventsAsync() as AppDispatch)) as unknown as CalendarEvent[];
const interval = setInterval(async () =>{
const fetchedEvents: CalendarEvent[] = (await mainDispatch(fetchEventsAsync() as AppDispatch)) as unknown as CalendarEvent[];

mainDispatch(SetCalendarEvents(fetchedEvents));
}
})();
});
mainDispatch(SetCalendarEvents(fetchedEvents));
}, 10000);

return () => {
clearInterval(interval);
};
}, [events]);

return (<>
<div className={"flex flex-col bg-body-gray items-center grow"}>
Expand All @@ -35,3 +37,4 @@ export default function EventsPage()
</>);
}


0 comments on commit de806d9

Please sign in to comment.