Profile
In this article, we look into the workflow of what happens when a user visits own profile or visits other user profile.
Profile Page#
Profile Header#
The currentUserProfile which was stored during app initialization in the redux store is passed to the ProfileHeader.jsx component which renders the profile photo, displayName, followerCount and followingCount.
Profile Content#
Renders fours tabs:<AboutTab /> , <PhotosTab />, <EventsTab /> and <FollowingTab />.
About Tab#
ProfileContent.jsx component passes profile and currentUser to the <AboutTab> component.
A user can edit his/her about section using edit option visible. This option is not visible to other users looking into your profile and vice-versa.
PhotosTab#
We fetch photos of the user from firestore.
We then dispatch listenToUserPhotos which saves our fetched photos in our redux store.
A user can upload and set profile photo.
Uploading photo : When user clicks on
Add Photobutton in Photos Tab,<PhotoWidgetComponent />renders and user needs to go through 3 steps.
Uploading photos involves three steps:Step 1 Add Photo : A
<PhotoWidgetDropzone /> renders. We use react-dropzone. As the name suggest we drag and drop or simply select our photo from our local system. On selecting it then saves our selected file in a located state namedfile.Step 2 Resize : A
<PhotoWidgetCropper />renders. We use react-cropper. We crop the image and save the cropped image in our local state namedimage.Step 3 Preview & Upload : We are shown the preview of the selected image and we have two options to upload or cancel the process.
On clicking upload:
After upload completes, we get a download url from firebase storage by
getDownloadUrl(). We then update user profile photo in the firestore, currentUser and photo collection.On clicking cancel, we reset the process
Setting profile photo : Setting a photo requires updation of photoURL at various fields. These are events, attendees and userFollowing docs and also updating currentUser.
Events Tab#
The Events Tab renders yet three other tabs for past events, future events and hosting events of the user.
ProfileContent.jsx passes profile which is either currentUserProfile or selectedUserProfile to EventsTab.jsx. Based on the current active tab events are fetched from the firestore.
After fetching the events from the firestore we dispatch an action listenToUserEvents which is responsible for storing the fetched events in our redux store under profileEvents.
Following Tab#
We store the logic for followers tab and following tab in a single file named Following Tab.
ProfileContent.jsx component passes the activeTab and the profile, again the profile is either selectedUserProfile our currentUserProfile. Based on the activeTab we call getFollowersCollection that fetches the user's followers or following collection.
After fetching followers or following collection we dispatch an action listenToFollowers or listenToFollowing accordingly that stores the following/followers count as an array in our redux store.
