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.
#
WorkflowWhen 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 thanstartDate
will be fetched. - filter set to
isGoing
: events greater thanstartDate
and to which the logged in user is going(by matchingattendeeIds
withuser.id
) will be fetched. - filter set to
isHost
: event that logged in user is hosting(by comparinghostId
withuser.id
) and events greater than thestartDate
will 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