Fetching Events
When visit the events page we fetch the events from the firestore. Let's us see how the events are fetched in detail.
Workflow#
When the EventDashboard page loads useEffect runs and fetchEvents action is dispatched to which filter,startDate, limit is passed. The fetchEvents action in turn dispatches fetchEventsFromFirestore
fetchEventsFromFirestore returns us the snapshot of all the docs with the condition set as follows and limit set to 2 in our case :
- filter set to
all: events greater thanstartDatewill be fetched. - filter set to
isGoing: events greater thanstartDateand to which the logged in user is going(by matchingattendeeIdswithuser.id) will be fetched. - filter set to
isHost: event that logged in user is hosting(by comparinghostIdwithuser.id) and events greater than thestartDatewill be fetched.
The snapshot of all the documents returned by fetchEventsFromFirestore(2 docs in our case) are then used to calculate lastVisible, moreEvents and events.
This all is done for pagination. More on it here
Another action FETCH_EVENTS is dispatched that set the redux state as
Detailed state below :
The fetched events are then passed to EventList component and then to EventListItem which renders the events to the screen.
Useful Resources#
- If you find something unclear or unable to visualize components you can always find pictorial representation of the components here
