diff options
author | Ashm Walia <ashmwalia@outlook.com> | 2021-01-31 03:49:46 -0800 |
---|---|---|
committer | Ashm Walia <ashmwalia@outlook.com> | 2021-01-31 03:49:46 -0800 |
commit | 60d281814c60a471598746b4dad8f3d18be0931c (patch) | |
tree | 20d1c99eb593fa999bce1376c40c22b78ebefc20 | |
parent | 69b337ed7c3844cf04a6bd1c0557ba598735f34e (diff) |
Fixed
-rw-r--r-- | src/components/notifications/Notification.tsx | 42 | ||||
-rw-r--r-- | src/constants/strings.ts | 3 | ||||
-rw-r--r-- | src/store/actions/userX.ts | 81 | ||||
-rw-r--r-- | src/types/types.ts | 8 |
4 files changed, 121 insertions, 13 deletions
diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index d40c65ed..6d473b11 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -2,7 +2,8 @@ import {useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; import {Alert, Image, StyleSheet, Text, View} from 'react-native'; import {TouchableWithoutFeedback} from 'react-native-gesture-handler'; -import {useDispatch, useStore} from 'react-redux'; +import {useDispatch, useSelector, useStore} from 'react-redux'; +import {ERROR_DELETED_OBJECT} from '../../constants/strings'; import { loadImageFromURL, loadMoments, @@ -12,15 +13,17 @@ import { acceptFriendRequest, declineFriendRequest, loadUserNotifications, + loadUserX, + loadUserXSpecifics, updateReplyPosted, updateUserXFriends, } from '../../store/actions'; +import {NO_MOMENTS} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {MomentType, NotificationType, ScreenType} from '../../types'; import { fetchUserX, getTokenOrLogout, - handleOpenSocialUrlOnBrowser, SCREEN_HEIGHT, userXInStore, } from '../../utils'; @@ -52,6 +55,7 @@ const Notification: React.FC<NotificationProps> = (props) => { const [avatar, setAvatar] = useState<string | undefined>(undefined); const [momentURI, setMomentURI] = useState<string | undefined>(undefined); const backgroundColor = unread ? '#DCF1F1' : 'rgba(0,0,0,0)'; + const [onTapLoadProfile, setOnTapLoadProfile] = useState<boolean>(false); useEffect(() => { (async () => { @@ -63,6 +67,22 @@ const Notification: React.FC<NotificationProps> = (props) => { }, []); useEffect(() => { + if (onTapLoadProfile) { + dispatch( + loadUserXSpecifics( + {userId: id, username: username}, + ['Profile', 'Moments'], + screenType, + ), + ); + } + return () => { + setOnTapLoadProfile(false); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [onTapLoadProfile]); + + useEffect(() => { let mounted = true; const loadMomentImage = async (moment_id: string) => { const response = await loadMomentThumbnail(moment_id); @@ -101,7 +121,7 @@ const Notification: React.FC<NotificationProps> = (props) => { case 'CMT': //Notification object is set to null if the comment / comment_thread / moment gets deleted if (!notification_object) { - Alert.alert('The comment / moment was probably deleted by the user'); + Alert.alert(ERROR_DELETED_OBJECT); break; } let {moment_id} = notification_object; @@ -125,17 +145,13 @@ const Notification: React.FC<NotificationProps> = (props) => { if (!moment) { let moments: MomentType[] = []; try { - if (!userXInStore(state, screenType, id)) { - const token = await getTokenOrLogout(dispatch); - moments = await loadMoments(id, token); - } else { - moments = state.userX[screenType][id].moments; - } + //Populate local state in the mean time + setOnTapLoadProfile(true); + const token = await getTokenOrLogout(dispatch); + moments = await loadMoments(id, token); } catch (err) { console.log(err); } - - setTimeout(() => {}, 700); moment = moments?.find((m) => m.moment_id === moment_id); userXId = id; } @@ -165,7 +181,9 @@ const Notification: React.FC<NotificationProps> = (props) => { }; const handleAcceptRequest = async () => { - await dispatch(acceptFriendRequest({id, username, first_name, last_name})); + await dispatch( + acceptFriendRequest({id, username, first_name, last_name, thumbnail_url}), + ); await dispatch(updateUserXFriends(id, state)); dispatch(loadUserNotifications()); }; diff --git a/src/constants/strings.ts b/src/constants/strings.ts index b0886513..9680320a 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -10,6 +10,7 @@ export const ERROR_CATEGORY_CREATION = 'There was a problem creating your catego export const ERROR_CATEGORY_UPDATE = 'There was a problem updating your categories. Please refresh and try again'; export const ERROR_DELETE_CATEGORY = 'There was a problem while deleting category. Please try again'; export const ERROR_DELETE_MOMENT = 'Unable to delete moment, please try again later!'; +export const ERROR_DELETED_OBJECT = 'Oh sad! Looks like the comment / moment was deleted by the user'; export const ERROR_DOUBLE_CHECK_CONNECTION = 'Please double-check your network connection and retry'; export const ERROR_DUP_OLD_PWD = 'You may not use a previously used password'; export const ERROR_EMAIL_IN_USE = 'Email already in use, please try another one'; @@ -52,4 +53,4 @@ export const UPLOAD_MOMENT_PROMPT_ONE_MESSAGE = 'Post your first moment to\n con export const UPLOAD_MOMENT_PROMPT_THREE_HEADER = 'Continue to build your profile'; export const UPLOAD_MOMENT_PROMPT_THREE_MESSAGE = 'Continue to personalize your own digital space in\nthis community by filling your profile with\ncategories and moments!'; export const UPLOAD_MOMENT_PROMPT_TWO_HEADER = 'Create a new category'; -export const UPLOAD_MOMENT_PROMPT_TWO_MESSAGE = 'You can now create new categories \nand continue to fill your profile with moments!'; +export const UPLOAD_MOMENT_PROMPT_TWO_MESSAGE = 'You can now create new categories \nand continue to fill your profile with moments!';
\ No newline at end of file diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index 07bea678..af8188f1 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -1,3 +1,4 @@ +import {UserXSpecifics} from './../../types/types'; import {userXInStore} from './../../utils/'; import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils'; import {UserType, ScreenType} from '../../types/types'; @@ -85,6 +86,86 @@ export const loadUserX = ( } }; +export const loadUserXSpecifics = ( + user: UserType, + specifics: UserXSpecifics[], + screenType: ScreenType, +): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( + dispatch, +) => { + const {userId} = user; + await dispatch({type: userXRequested.type, payload: {screenType, userId}}); + await dispatch({ + type: userXUserFetched.type, + payload: {screenType, userId, user}, + }); + const token = await getTokenOrLogout(dispatch); + for (let specific of specifics) { + switch (specific) { + case 'Profile': + console.log(specific); + loadProfileInfo(token, userId).then((data) => { + dispatch({ + type: userXProfileFetched.type, + payload: {screenType, userId, data}, + }); + }); + break; + case 'Socials': + loadAllSocialsForUser(userId).then((data) => + dispatch({ + type: userXSocialsFetched.type, + payload: {screenType, userId, data}, + }), + ); + break; + case 'Avatar': + loadAvatar(userId, false).then((data) => + dispatch({ + type: userXAvatarFetched.type, + payload: {screenType, userId, data}, + }), + ); + break; + case 'Cover': + loadCover(token, userId).then((data) => + dispatch({ + type: userXCoverFetched.type, + payload: {screenType, userId, data}, + }), + ); + break; + case 'Friends': + loadFriends(userId, token).then((data) => + dispatch({ + type: userXFriendsFetched.type, + payload: {screenType, userId, data}, + }), + ); + break; + case 'Moments': + console.log(specific); + loadMoments(userId, token).then((data) => + dispatch({ + type: userXMomentsFetched.type, + payload: {screenType, userId, data}, + }), + ); + break; + case 'MomentCategories': + loadMomentCategories(userId, token).then((data) => { + dispatch({ + type: userXMomentCategoriesFetched.type, + payload: {screenType, userId, data}, + }); + }); + break; + default: + break; + } + } +}; + export const updateUserXFriends = ( userId: string, state: RootState, diff --git a/src/types/types.ts b/src/types/types.ts index 1775cd5f..e9abc789 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -186,3 +186,11 @@ export type NotificationType = { }; export type TypeOfComment = 'Comment' | 'Thread'; +export type UserXSpecifics = + | 'Profile' + | 'Socials' + | 'Avatar' + | 'Cover' + | 'Friends' + | 'Moments' + | 'MomentCategories'; |