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/actions | |
| 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/actions')
| -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 |
4 files changed, 61 insertions, 80 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}, }), ); |
