diff options
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/actions/taggUsers.ts | 3 | ||||
-rw-r--r-- | src/store/actions/user.ts | 7 | ||||
-rw-r--r-- | src/store/actions/userX.ts | 83 | ||||
-rw-r--r-- | src/store/initialStates.ts | 16 |
4 files changed, 55 insertions, 54 deletions
diff --git a/src/store/actions/taggUsers.ts b/src/store/actions/taggUsers.ts index 72ce848b..0cd94e92 100644 --- a/src/store/actions/taggUsers.ts +++ b/src/store/actions/taggUsers.ts @@ -1,5 +1,5 @@ import {Action, ThunkAction} from '@reduxjs/toolkit'; -import {getAllExploreSections, loadRecentlySearchedUsers} from '../../services'; +import {loadRecentlySearchedUsers} from '../../services'; import {taggUsersFetched} from '../reducers'; import {RootState} from '../rootReducer'; @@ -11,7 +11,6 @@ export const loadRecentlySearched = (): ThunkAction< > => async (dispatch) => { try { const recentSearches = await loadRecentlySearchedUsers(); - getAllExploreSections(); dispatch({ type: taggUsersFetched.type, payload: {recentSearches}, diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 4f1da47c..46f96d9a 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,7 +1,6 @@ import {Action, ThunkAction} from '@reduxjs/toolkit'; import { - loadAvatar, - loadCover, + getProfilePic, loadProfileInfo, sendSuggestedPeopleLinked, } from '../../services'; @@ -43,8 +42,8 @@ export const loadUserData = ( const token = await getTokenOrLogout(dispatch); const [profile, avatar, cover] = await Promise.all([ loadProfileInfo(token, user.userId), - loadAvatar(user.userId, false), - loadCover(token, user.userId), + getProfilePic(token, user.userId, 'profile'), + getProfilePic(token, user.userId, 'header'), ]); dispatch({ type: userDetailsFetched.type, diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index 07bea678..f32a4d8f 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -1,28 +1,27 @@ -import {userXInStore} from './../../utils/'; -import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils'; -import {UserType, ScreenType} from '../../types/types'; -import {RootState} from '../rootReducer'; import {Action, ThunkAction} from '@reduxjs/toolkit'; +import moment from 'moment'; import { - userXRequested, + fetchUserProfile, + loadFriends, + loadMoments, + loadProfileInfo, +} from '../../services'; +import {ScreenType, UserType} from '../../types/types'; +import { + resetScreen, userXAvatarFetched, - userXFriendsFetched, userXCoverFetched, + userXFriendsFetched, + userXMomentCategoriesFetched, userXMomentsFetched, userXProfileFetched, + userXRequested, userXSocialsFetched, userXUserFetched, - userXMomentCategoriesFetched, - resetScreen, } from '../reducers'; -import { - loadProfileInfo, - loadAvatar, - loadCover, - loadFriends, - loadMomentCategories, - loadMoments, -} from '../../services'; +import {RootState} from '../rootReducer'; +import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils'; +import {userXInStore} from './../../utils/'; export const loadUserX = ( user: UserType, @@ -38,30 +37,40 @@ export const loadUserX = ( payload: {screenType, userId, user}, }); const token = await getTokenOrLogout(dispatch); - loadProfileInfo(token, userId).then((data) => { - dispatch({ - type: userXProfileFetched.type, - payload: {screenType, userId, data}, - }); + fetchUserProfile(userId, token).then((profile) => { + if (profile) { + const birthday = profile.profile_info.birthday; + dispatch({ + type: userXProfileFetched.type, + payload: { + screenType, + userId, + data: { + ...profile.profile_info, + birthday: birthday && moment(birthday).format('YYYY-MM-DD'), + }, + }, + }); + dispatch({ + type: userXAvatarFetched.type, + payload: {screenType, userId, data: profile.profile_pic}, + }); + dispatch({ + type: userXCoverFetched.type, + payload: {screenType, userId, data: profile.header_pic}, + }); + dispatch({ + type: userXMomentCategoriesFetched.type, + payload: {screenType, userId, data: profile.moment_categories}, + }); + } }); - loadAllSocialsForUser(userId).then((data) => + loadAllSocialsForUser(userId, token).then((data) => dispatch({ type: userXSocialsFetched.type, payload: {screenType, userId, data}, }), ); - loadAvatar(userId, false).then((data) => - dispatch({ - type: userXAvatarFetched.type, - payload: {screenType, userId, data}, - }), - ); - loadCover(token, userId).then((data) => - dispatch({ - type: userXCoverFetched.type, - payload: {screenType, userId, data}, - }), - ); loadFriends(userId, token).then((data) => dispatch({ type: userXFriendsFetched.type, @@ -74,12 +83,6 @@ export const loadUserX = ( payload: {screenType, userId, data}, }), ); - loadMomentCategories(userId, token).then((data) => { - dispatch({ - type: userXMomentCategoriesFetched.type, - payload: {screenType, userId, data}, - }); - }); } catch (error) { console.log(error); } diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index b43e4a1d..47ab8f39 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -1,17 +1,16 @@ import {CommentThreadType} from './../types/types'; import { - ExploreSectionType, MomentType, NotificationType, ProfilePreviewType, - ProfileType, + ProfileInfoType, ScreenType, SocialAccountType, UserType, UserXType, } from '../types'; -export const NO_PROFILE: ProfileType = { +export const NO_PROFILE: ProfileInfoType = { biography: '', website: '', name: '', @@ -26,6 +25,7 @@ export const NO_PROFILE: ProfileType = { tiktok: '', friendship_status: 'no_record', friendship_requester_id: '', + is_private: true, }; export const EMPTY_MOMENTS_LIST = <MomentType[]>[]; @@ -41,9 +41,9 @@ export const EMPTY_PROFILE_PREVIEW_LIST = <ProfilePreviewType[]>[]; export const NO_USER_DATA = { user: <UserType>NO_USER, - profile: <ProfileType>NO_PROFILE, - avatar: <string | null>'', - cover: <string | null>'', + profile: <ProfileInfoType>NO_PROFILE, + avatar: <string | undefined>undefined, + cover: <string | undefined>undefined, isOnboardedUser: false, newVersionAvailable: false, newNotificationReceived: false, @@ -98,8 +98,8 @@ export const EMPTY_USER_X = <UserXType>{ socialAccounts: NO_SOCIAL_ACCOUNTS, user: NO_USER, profile: NO_PROFILE, - avatar: '', - cover: '', + avatar: undefined, + cover: undefined, }; /** |