From 88433cda2938a2fa4f6bf3e4b2282fe0095dfe71 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 07:01:41 -0800 Subject: Add sp_swipe_tutorial to ProfileType: --- src/store/initialStates.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/store') diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index 8d137a5d..aa391713 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -21,6 +21,7 @@ export const NO_PROFILE: ProfileType = { //Default to an invalid value and ignore it gracefully while showing tutorials / popups. profile_completion_stage: -1, + sp_swipe_tutorial: 0, snapchat: '', tiktok: '', friendship_status: 'no_record', -- cgit v1.2.3-70-g09d2 From e95ff2d483903b4d390c8dd0edf4ab60561b8334 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 07:03:02 -0800 Subject: Create thunk action + reducer to set new variable --- src/store/actions/user.ts | 33 +++++++++++++++++++++++++++++++-- src/store/reducers/userReducer.ts | 7 ++++++- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src/store') diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 5f49a103..98e1727b 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,7 +1,12 @@ -import { CommentThreadType } from './../../types/types'; +import {CommentThreadType} from './../../types/types'; import {RootState} from '../rootReducer'; import {UserType} from '../../types/types'; -import {loadProfileInfo, loadAvatar, loadCover} from '../../services'; +import { + loadProfileInfo, + loadAvatar, + loadCover, + editSPSwipeTutorial, +} from '../../services'; import {Action, ThunkAction} from '@reduxjs/toolkit'; import { userLoggedIn, @@ -13,6 +18,7 @@ import { setReplyPosted, } from '../reducers'; import {getTokenOrLogout} from '../../utils'; +import {spSwipeTutorialUpdated} from '../reducers/userReducer'; /** * Entry point to our store. @@ -140,3 +146,26 @@ export const logout = (): ThunkAction< console.log(error); } }; + +export const updateSPSwipeTutorial = ( + user: UserType, + data: number, +): ThunkAction< + Promise, + RootState, + unknown, + Action +> => async (dispatch) => { + try { + const success = await editSPSwipeTutorial(user); + if (success) { + dispatch({ + type: spSwipeTutorialUpdated.type, + payload: {sp_swipe_tutorial: data}, + }); + } + return success; + } catch (error) { + console.log('Error while updating suggested people linked state: ', error); + } +}; diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index 1e575339..b353cc60 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -1,4 +1,4 @@ -import {createSlice, Action} from '@reduxjs/toolkit'; +import {createSlice} from '@reduxjs/toolkit'; import {NO_USER_DATA} from '../initialStates'; /** @@ -46,6 +46,10 @@ const userDataSlice = createSlice({ state.profile.profile_completion_stage = action.payload.stage; }, + spSwipeTutorialUpdated: (state, action) => { + state.profile.sp_swipe_tutorial = action.payload.sp_swipe_tutorial; + }, + setIsOnboardedUser: (state, action) => { state.isOnboardedUser = action.payload.isOnboardedUser; }, @@ -68,5 +72,6 @@ export const { setIsOnboardedUser, setNewNotificationReceived, setReplyPosted, + spSwipeTutorialUpdated, } = userDataSlice.actions; export const userDataReducer = userDataSlice.reducer; -- cgit v1.2.3-70-g09d2 From da61f04d037d92fce7cf9852a3be79eb41158d5a Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 14:04:04 -0800 Subject: dispatching reducer while updating backend --- src/services/UserProfileService.ts | 1 - src/store/actions/user.ts | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'src/store') diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 9061dd5e..3bca66f3 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -336,7 +336,6 @@ export const editSPSwipeTutorial = async (user: UserType) => { body: request, }); if (response.status === 200) { - console.log('updatedbackend'); return true; } else { return false; diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 98e1727b..50f810e4 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -158,12 +158,10 @@ export const updateSPSwipeTutorial = ( > => async (dispatch) => { try { const success = await editSPSwipeTutorial(user); - if (success) { - dispatch({ - type: spSwipeTutorialUpdated.type, - payload: {sp_swipe_tutorial: data}, - }); - } + dispatch({ + type: spSwipeTutorialUpdated.type, + payload: {sp_swipe_tutorial: data}, + }); return success; } catch (error) { console.log('Error while updating suggested people linked state: ', error); -- cgit v1.2.3-70-g09d2 From eeac3efd296656a0ef0a1e5797fec7c9955c7a12 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 11 Feb 2021 17:14:44 -0500 Subject: non-ui-blocking --- src/screens/suggestedPeople/AnimatedTutorial.tsx | 2 +- src/store/actions/user.ts | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src/store') diff --git a/src/screens/suggestedPeople/AnimatedTutorial.tsx b/src/screens/suggestedPeople/AnimatedTutorial.tsx index 9606eacb..8ebdaea6 100644 --- a/src/screens/suggestedPeople/AnimatedTutorial.tsx +++ b/src/screens/suggestedPeople/AnimatedTutorial.tsx @@ -19,7 +19,7 @@ const AnimatedTutorial: React.FC = () => { * Make call to edit profile endpoint with suggested people === 1 */ const data = 1; - await dispatch(updateSPSwipeTutorial(user, data)); + dispatch(updateSPSwipeTutorial(user, data)); navigation.pop(); }; return ( diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 9f1855ce..990f9260 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,14 +1,10 @@ -import {CommentThreadType} from './../../types/types'; -import {RootState} from '../rootReducer'; -import {UserType} from '../../types/types'; +import {Action, ThunkAction} from '@reduxjs/toolkit'; import { - loadProfileInfo, + editSPSwipeTutorial, loadAvatar, loadCover, - editSPSwipeTutorial, + loadProfileInfo, } from '../../services'; -import {Action, ThunkAction} from '@reduxjs/toolkit'; -import {loadAvatar, loadCover, loadProfileInfo} from '../../services'; import {UserType} from '../../types/types'; import {getTokenOrLogout} from '../../utils'; import { @@ -21,7 +17,6 @@ import { userDetailsFetched, userLoggedIn, } from '../reducers'; -import {getTokenOrLogout} from '../../utils'; import {spSwipeTutorialUpdated} from '../reducers/userReducer'; import {RootState} from '../rootReducer'; import {CommentThreadType} from './../../types/types'; @@ -178,12 +173,12 @@ export const updateSPSwipeTutorial = ( Action > => async (dispatch) => { try { - const success = await editSPSwipeTutorial(user); + // update store first, assume success dispatch({ type: spSwipeTutorialUpdated.type, payload: {sp_swipe_tutorial: data}, }); - return success; + return await editSPSwipeTutorial(user); } catch (error) { console.log('Error while updating suggested people linked state: ', error); } -- cgit v1.2.3-70-g09d2