diff options
| author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2021-01-31 13:16:41 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-31 13:16:41 -0800 |
| commit | b7509400433169e698450e4a7667d268439dcf41 (patch) | |
| tree | 92fcfb0f91d1498f8a36762a1ee650f17dbb3af8 /src/store | |
| parent | ce18efb5318c230944167d42bbde827aaca4ee4a (diff) | |
| parent | 60d281814c60a471598746b4dad8f3d18be0931c (diff) | |
Merge pull request #209 from ashmgarv/tma-612-611-redesign-comments
[TMA 612/611] Frontend
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/actions/user.ts | 17 | ||||
| -rw-r--r-- | src/store/actions/userX.ts | 81 | ||||
| -rw-r--r-- | src/store/initialStates.ts | 2 | ||||
| -rw-r--r-- | src/store/reducers/userReducer.ts | 5 |
4 files changed, 105 insertions, 0 deletions
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 0b1ea789..5f49a103 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,21 @@ export const updateNewNotificationReceived = ( } }; +export const updateReplyPosted = ( + replyPosted: CommentThreadType | undefined, +): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( + dispatch, +) => { + try { + dispatch({ + type: setReplyPosted.type, + payload: {replyPosted}, + }); + } catch (error) { + console.log(error); + } +}; + export const logout = (): ThunkAction< Promise<void>, RootState, 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/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: <string | null>'', isOnboardedUser: false, newNotificationReceived: false, + replyPosted: <CommentThreadType | undefined>undefined, }; export const NO_FRIENDS_DATA = { diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index ce497677..1e575339 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -53,6 +53,10 @@ const userDataSlice = createSlice({ setNewNotificationReceived: (state, action) => { state.newNotificationReceived = action.payload.newNotificationReceived; }, + + setReplyPosted: (state, action) => { + state.replyPosted = action.payload.replyPosted; + }, }, }); @@ -63,5 +67,6 @@ export const { profileCompletionStageUpdated, setIsOnboardedUser, setNewNotificationReceived, + setReplyPosted, } = userDataSlice.actions; export const userDataReducer = userDataSlice.reducer; |
