diff options
| author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-12-30 11:36:44 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 14:36:44 -0500 |
| commit | 38661e00281363b0f4ad32f0b29d739e1ca09164 (patch) | |
| tree | 316cd837b6cc6ae24783f1d93d6c9ee7fb898f68 /src/store | |
| parent | bd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (diff) | |
[TMA - 457]Change followers to friends (#149)
* One commit to replace followers with friends
* Move block unblock to drawer and some cosmetic changes
* Options to edit own profile when viewing
* Changes for University Class
* Small fix
* Made ProfileOnboarding a scroll view and other small changes
* Small fix
* Small fix thanks to ivan and tanmay
* Add ?
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/actions/index.ts | 2 | ||||
| -rw-r--r-- | src/store/actions/userFollow.ts | 57 | ||||
| -rw-r--r-- | src/store/actions/userFriends.ts | 52 | ||||
| -rw-r--r-- | src/store/actions/userX.ts | 30 | ||||
| -rw-r--r-- | src/store/initialStates.ts | 13 | ||||
| -rw-r--r-- | src/store/reducers/index.ts | 2 | ||||
| -rw-r--r-- | src/store/reducers/userFollowReducer.ts | 27 | ||||
| -rw-r--r-- | src/store/reducers/userFriendsReducer.ts | 25 | ||||
| -rw-r--r-- | src/store/reducers/userXReducer.ts | 13 | ||||
| -rw-r--r-- | src/store/rootReducer.ts | 4 |
10 files changed, 98 insertions, 127 deletions
diff --git a/src/store/actions/index.ts b/src/store/actions/index.ts index 285ca4de..337bc325 100644 --- a/src/store/actions/index.ts +++ b/src/store/actions/index.ts @@ -1,5 +1,5 @@ export * from './user'; -export * from './userFollow'; +export * from './userFriends'; export * from './userMoments'; export * from './momentCategories'; export * from './socials'; diff --git a/src/store/actions/userFollow.ts b/src/store/actions/userFollow.ts deleted file mode 100644 index e23bbfc0..00000000 --- a/src/store/actions/userFollow.ts +++ /dev/null @@ -1,57 +0,0 @@ -import {getTokenOrLogout} from './../../utils'; -import {RootState} from '../rootReducer'; -import {ProfilePreviewType, UserType} from '../../types/types'; -import { - followOrUnfollowUser, - loadFollowers, - loadFollowing, -} from '../../services'; -import {Action, ThunkAction} from '@reduxjs/toolkit'; -import {userFollowFetched, updateFollowing, userLoggedIn} from '../reducers'; - -export const loadFollowData = ( - userId: string, -): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( - dispatch, -) => { - try { - const token = await getTokenOrLogout(dispatch); - const followers = await loadFollowers(userId, token); - const following = await loadFollowing(userId, token); - dispatch({ - type: userFollowFetched.type, - payload: {followers, following}, - }); - } catch (error) { - console.log(error); - } -}; - -export const followUnfollowUser = ( - follower: UserType, - followed: ProfilePreviewType, - isFollowed: boolean, -): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( - dispatch, -) => { - try { - const token = await getTokenOrLogout(dispatch); - const success = await followOrUnfollowUser( - follower.userId, - followed.id, - token, - isFollowed, - ); - if (success) { - dispatch({ - type: updateFollowing.type, - payload: { - isFollowed, - data: followed, - }, - }); - } - } catch (error) { - console.log(error); - } -}; diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts new file mode 100644 index 00000000..24e32607 --- /dev/null +++ b/src/store/actions/userFriends.ts @@ -0,0 +1,52 @@ +import {getTokenOrLogout} from '../../utils'; +import {RootState} from '../rootReducer'; +import {ProfilePreviewType, UserType} from '../../types/types'; +import {friendOrUnfriendUser, loadFriends} from '../../services'; +import {Action, ThunkAction} from '@reduxjs/toolkit'; +import {userFriendsFetched, updateFriends} from '../reducers'; + +export const loadFriendsData = ( + userId: string, +): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( + dispatch, +) => { + try { + const token = await getTokenOrLogout(dispatch); + const friends = await loadFriends(userId, token); + dispatch({ + type: userFriendsFetched.type, + payload: {friends}, + }); + } catch (error) { + console.log(error); + } +}; + +export const friendUnfriendUser = ( + user: UserType, + friend: ProfilePreviewType, + isFriend: boolean, +): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( + dispatch, +) => { + try { + const token = await getTokenOrLogout(dispatch); + const success = await friendOrUnfriendUser( + user.userId, + friend.id, + token, + isFriend, + ); + if (success) { + dispatch({ + type: updateFriends.type, + payload: { + isFriend, + data: friend, + }, + }); + } + } catch (error) { + console.log(error); + } +}; diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index e313546e..0f87012d 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -1,4 +1,3 @@ -import {loadMomentCategories} from './../../services/MomentCategoryService'; import {userXInStore} from './../../utils/'; import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils'; import {UserType, ScreenType} from '../../types/types'; @@ -7,8 +6,7 @@ import {Action, ThunkAction} from '@reduxjs/toolkit'; import { userXRequested, userXAvatarFetched, - userXFollowersFetched, - userXFollowingFetched, + userXFriendsFetched, userXCoverFetched, userXMomentsFetched, userXProfileFetched, @@ -21,8 +19,8 @@ import { loadProfileInfo, loadAvatar, loadCover, - loadFollowers, - loadFollowing, + loadFriends, + loadMomentCategories, loadMoments, } from '../../services'; @@ -64,15 +62,9 @@ export const loadUserX = ( payload: {screenType, userId, data}, }), ); - loadFollowers(userId, token).then((data) => + loadFriends(userId, token).then((data) => dispatch({ - type: userXFollowersFetched.type, - payload: {screenType, userId, data}, - }), - ); - loadFollowing(userId, token).then((data) => - dispatch({ - type: userXFollowingFetched.type, + type: userXFriendsFetched.type, payload: {screenType, userId, data}, }), ); @@ -93,7 +85,7 @@ export const loadUserX = ( } }; -export const updateUserXFollowersAndFollowing = ( +export const updateUserXFriends = ( userId: string, state: RootState, ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async ( @@ -104,15 +96,9 @@ export const updateUserXFollowersAndFollowing = ( const token = await getTokenOrLogout(dispatch); screens.forEach((screenType) => { if (userXInStore(state, screenType, userId)) { - loadFollowers(userId, token).then((data) => - dispatch({ - type: userXFollowersFetched.type, - payload: {screenType, userId, data}, - }), - ); - loadFollowing(userId, token).then((data) => + loadFriends(userId, token).then((data) => dispatch({ - type: userXFollowingFetched.type, + type: userXFriendsFetched.type, payload: {screenType, userId, data}, }), ); diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index b75569d6..883c0487 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -16,6 +16,7 @@ export const NO_PROFILE: ProfileType = { name: '', gender: '', birthday: undefined, + university_class: 2021, snapchat: '', tiktok: '', }; @@ -38,13 +39,12 @@ export const NO_USER_DATA = { cover: <string | null>'', }; -export const NO_NOTIFICATIONS = { - notifications: EMPTY_NOTIFICATIONS_LIST, +export const NO_FRIENDS_DATA = { + friends: EMPTY_PROFILE_PREVIEW_LIST, }; -export const NO_FOLLOW_DATA = { - followers: EMPTY_PROFILE_PREVIEW_LIST, - following: EMPTY_PROFILE_PREVIEW_LIST, +export const NO_NOTIFICATIONS = { + notifications: EMPTY_NOTIFICATIONS_LIST, }; export const NO_MOMENTS = { @@ -97,8 +97,7 @@ export const DUMMY_USERID = 'ID-1234-567'; export const DUMMY_USERNAME = 'tagg_userX'; export const EMPTY_USER_X = <UserXType>{ - followers: EMPTY_PROFILE_PREVIEW_LIST, - following: EMPTY_PROFILE_PREVIEW_LIST, + friends: EMPTY_PROFILE_PREVIEW_LIST, moments: EMPTY_MOMENTS_LIST, momentCategories: MOMENT_CATEGORIES_MAP, socialAccounts: NO_SOCIAL_ACCOUNTS, diff --git a/src/store/reducers/index.ts b/src/store/reducers/index.ts index f525eb81..c9463639 100644 --- a/src/store/reducers/index.ts +++ b/src/store/reducers/index.ts @@ -1,4 +1,4 @@ -export * from './userFollowReducer'; +export * from './userFriendsReducer'; export * from './userReducer'; export * from './userMomentsReducer'; export * from './userSocialsReducer'; diff --git a/src/store/reducers/userFollowReducer.ts b/src/store/reducers/userFollowReducer.ts deleted file mode 100644 index 55e16532..00000000 --- a/src/store/reducers/userFollowReducer.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {createSlice} from '@reduxjs/toolkit'; -import {act} from 'react-test-renderer'; -import {NO_FOLLOW_DATA} from '../initialStates'; - -const userFollowSlice = createSlice({ - name: 'userFollow', - initialState: NO_FOLLOW_DATA, - reducers: { - userFollowFetched: (state, action) => { - state.followers = action.payload.followers; - state.following = action.payload.following; - }, - - updateFollowing: (state, action) => { - const {isFollowed, data} = action.payload; - if (!isFollowed) state.following.push(data); - else { - state.following = state.following.filter( - (follow) => follow.username !== data.username, - ); - } - }, - }, -}); - -export const {userFollowFetched, updateFollowing} = userFollowSlice.actions; -export const userFollowReducer = userFollowSlice.reducer; diff --git a/src/store/reducers/userFriendsReducer.ts b/src/store/reducers/userFriendsReducer.ts new file mode 100644 index 00000000..2041a181 --- /dev/null +++ b/src/store/reducers/userFriendsReducer.ts @@ -0,0 +1,25 @@ +import {createSlice} from '@reduxjs/toolkit'; +import {NO_FRIENDS_DATA} from '../initialStates'; + +const userFriendsSlice = createSlice({ + name: 'userFriends', + initialState: NO_FRIENDS_DATA, + reducers: { + userFriendsFetched: (state, action) => { + state.friends = action.payload.friends; + }, + + updateFriends: (state, action) => { + const {isFriend, data} = action.payload; + if (!isFriend) state.friends.push(data); + else { + state.friends = state.friends.filter( + (friend) => friend.username !== data.username, + ); + } + }, + }, +}); + +export const {userFriendsFetched, updateFriends} = userFriendsSlice.actions; +export const userFriendsReducer = userFriendsSlice.reducer; diff --git a/src/store/reducers/userXReducer.ts b/src/store/reducers/userXReducer.ts index bb142864..fa1598b2 100644 --- a/src/store/reducers/userXReducer.ts +++ b/src/store/reducers/userXReducer.ts @@ -38,16 +38,10 @@ const userXSlice = createSlice({ ].moments = action.payload.data; }, - userXFollowersFetched: (state, action) => { + userXFriendsFetched: (state, action) => { state[<ScreenType>action.payload.screenType][ action.payload.userId - ].followers = action.payload.data; - }, - - userXFollowingFetched: (state, action) => { - state[<ScreenType>action.payload.screenType][ - action.payload.userId - ].following = action.payload.data; + ].friends = action.payload.data; }, userXAvatarFetched: (state, action) => { @@ -80,8 +74,7 @@ export const { userXUserFetched, userXRequested, userXAvatarFetched, - userXFollowersFetched, - userXFollowingFetched, + userXFriendsFetched, userXCoverFetched, userXMomentsFetched, userXProfileFetched, diff --git a/src/store/rootReducer.ts b/src/store/rootReducer.ts index 7940b1fe..68a5c67c 100644 --- a/src/store/rootReducer.ts +++ b/src/store/rootReducer.ts @@ -2,7 +2,7 @@ import {combineReducers} from 'redux'; import { userDataReducer, userSocialsReducer, - userFollowReducer, + userFriendsReducer, userMomentsReducer, taggUsersReducer, userBlockReducer, @@ -17,7 +17,7 @@ import { const rootReducer = combineReducers({ user: userDataReducer, - follow: userFollowReducer, + friends: userFriendsReducer, moments: userMomentsReducer, notifications: userNotificationsReducer, socialAccounts: userSocialsReducer, |
