From a3000926cb26d9ca2afba116d875653783fb622b Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Sun, 31 Jan 2021 02:25:53 -0800 Subject: Fixed --- src/store/actions/user.ts | 18 ++++++++++++++++++ src/store/initialStates.ts | 2 ++ src/store/reducers/userReducer.ts | 6 ++++++ 3 files changed, 26 insertions(+) (limited to 'src/store') diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 0b1ea789..af942592 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,3 +1,4 @@ +import { CommentThreadType } from './../../types/types'; import {RootState} from '../rootReducer'; import {UserType} from '../../types/types'; import {loadProfileInfo, loadAvatar, loadCover} from '../../services'; @@ -9,6 +10,7 @@ import { profileCompletionStageUpdated, setIsOnboardedUser, setNewNotificationReceived, + setReplyPosted, } from '../reducers'; import {getTokenOrLogout} from '../../utils'; @@ -111,6 +113,22 @@ export const updateNewNotificationReceived = ( } }; +export const updateReplyPosted = ( + replyPosted: CommentThreadType | undefined, +): ThunkAction, RootState, unknown, Action> => async ( + dispatch, +) => { + console.log(replyPosted); + try { + dispatch({ + type: setReplyPosted.type, + payload: {replyPosted}, + }); + } catch (error) { + console.log(error); + } +}; + export const logout = (): ThunkAction< Promise, RootState, diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index 2a5b76db..8d137a5d 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -1,3 +1,4 @@ +import {CommentThreadType} from './../types/types'; import { ExploreSectionType, MomentType, @@ -44,6 +45,7 @@ export const NO_USER_DATA = { cover: '', isOnboardedUser: false, newNotificationReceived: false, + replyPosted: undefined, }; export const NO_FRIENDS_DATA = { diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index ce497677..0ef739ac 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -53,6 +53,11 @@ const userDataSlice = createSlice({ setNewNotificationReceived: (state, action) => { state.newNotificationReceived = action.payload.newNotificationReceived; }, + + setReplyPosted: (state, action) => { + console.log(action.payload.replyPosted); + state.replyPosted = action.payload.replyPosted; + }, }, }); @@ -63,5 +68,6 @@ export const { profileCompletionStageUpdated, setIsOnboardedUser, setNewNotificationReceived, + setReplyPosted, } = userDataSlice.actions; export const userDataReducer = userDataSlice.reducer; -- cgit v1.2.3-70-g09d2 From 69b337ed7c3844cf04a6bd1c0557ba598735f34e Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Sun, 31 Jan 2021 02:35:25 -0800 Subject: Fixed comments --- src/components/notifications/Notification.tsx | 4 ---- src/store/actions/user.ts | 1 - src/store/reducers/userReducer.ts | 1 - 3 files changed, 6 deletions(-) (limited to 'src/store') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index e40153ea..d40c65ed 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -113,8 +113,6 @@ const Notification: React.FC = (props) => { comment_id = notification_object?.parent_comment?.comment_id; } - console.log('Problem'); - // Now find the moment we need to display let moment: MomentType | undefined = loggedInUserMoments?.find( (m) => m.moment_id === moment_id, @@ -128,7 +126,6 @@ const Notification: React.FC = (props) => { let moments: MomentType[] = []; try { if (!userXInStore(state, screenType, id)) { - console.log('Problem'); const token = await getTokenOrLogout(dispatch); moments = await loadMoments(id, token); } else { @@ -143,7 +140,6 @@ const Notification: React.FC = (props) => { userXId = id; } - console.log(moment); //Now if moment was found, navigate to the respective moment if (moment) { if (notification_object?.parent_comment) { diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index af942592..5f49a103 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -118,7 +118,6 @@ export const updateReplyPosted = ( ): ThunkAction, RootState, unknown, Action> => async ( dispatch, ) => { - console.log(replyPosted); try { dispatch({ type: setReplyPosted.type, diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index 0ef739ac..1e575339 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -55,7 +55,6 @@ const userDataSlice = createSlice({ }, setReplyPosted: (state, action) => { - console.log(action.payload.replyPosted); state.replyPosted = action.payload.replyPosted; }, }, -- cgit v1.2.3-70-g09d2 From 60d281814c60a471598746b4dad8f3d18be0931c Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Sun, 31 Jan 2021 03:49:46 -0800 Subject: Fixed --- src/components/notifications/Notification.tsx | 42 ++++++++++---- src/constants/strings.ts | 3 +- src/store/actions/userX.ts | 81 +++++++++++++++++++++++++++ src/types/types.ts | 8 +++ 4 files changed, 121 insertions(+), 13 deletions(-) (limited to 'src/store') 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 = (props) => { const [avatar, setAvatar] = useState(undefined); const [momentURI, setMomentURI] = useState(undefined); const backgroundColor = unread ? '#DCF1F1' : 'rgba(0,0,0,0)'; + const [onTapLoadProfile, setOnTapLoadProfile] = useState(false); useEffect(() => { (async () => { @@ -62,6 +66,22 @@ const Notification: React.FC = (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) => { @@ -101,7 +121,7 @@ const Notification: React.FC = (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 = (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 = (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, RootState, unknown, Action> => 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'; -- cgit v1.2.3-70-g09d2 From 85c9a80e8867ff5303bfcc49b79b8bc5f25a2f61 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Sun, 31 Jan 2021 20:47:03 -0800 Subject: Done --- src/store/actions/userX.ts | 81 ---------------------------------------------- src/types/types.ts | 8 ----- 2 files changed, 89 deletions(-) (limited to 'src/store') diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index af8188f1..07bea678 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -1,4 +1,3 @@ -import {UserXSpecifics} from './../../types/types'; import {userXInStore} from './../../utils/'; import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils'; import {UserType, ScreenType} from '../../types/types'; @@ -86,86 +85,6 @@ export const loadUserX = ( } }; -export const loadUserXSpecifics = ( - user: UserType, - specifics: UserXSpecifics[], - screenType: ScreenType, -): ThunkAction, RootState, unknown, Action> => 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 e9abc789..1775cd5f 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -186,11 +186,3 @@ export type NotificationType = { }; export type TypeOfComment = 'Comment' | 'Thread'; -export type UserXSpecifics = - | 'Profile' - | 'Socials' - | 'Avatar' - | 'Cover' - | 'Friends' - | 'Moments' - | 'MomentCategories'; -- cgit v1.2.3-70-g09d2