aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'src/store')
-rw-r--r--src/store/actions/momentCategories.tsx80
-rw-r--r--src/store/actions/notifications.ts29
-rw-r--r--src/store/actions/socials.ts62
-rw-r--r--src/store/actions/taggUsers.ts29
-rw-r--r--src/store/actions/user.ts389
-rw-r--r--src/store/actions/userBlock.ts80
-rw-r--r--src/store/actions/userFriends.ts346
-rw-r--r--src/store/actions/userMoments.ts60
-rw-r--r--src/store/actions/userX.ts257
-rw-r--r--src/store/reducers/userMomentsReducer.ts6
-rw-r--r--src/store/reducers/userSocialsReducer.ts6
-rw-r--r--src/store/reducers/userXReducer.ts5
12 files changed, 671 insertions, 678 deletions
diff --git a/src/store/actions/momentCategories.tsx b/src/store/actions/momentCategories.tsx
index c91e9ec8..bac27db2 100644
--- a/src/store/actions/momentCategories.tsx
+++ b/src/store/actions/momentCategories.tsx
@@ -11,54 +11,54 @@ import {getTokenOrLogout} from '../../utils';
* Load all categories for user
* @param userId id of the user for whom categories should be loaded
*/
-export const loadUserMomentCategories = (
- userId: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const categories = await loadMomentCategories(userId, token);
- dispatch({
- type: momentCategoriesFetched.type,
- payload: {categories},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadUserMomentCategories =
+ (
+ userId: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const categories = await loadMomentCategories(userId, token);
+ dispatch({
+ type: momentCategoriesFetched.type,
+ payload: {categories},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
/**
* Handle addition / deletion of categories for a user
* @param categories List of categories
* @param add true if the call to his function is to add categories
*/
-export const updateMomentCategories = (
- categories: string[],
- add: boolean,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- let success = false;
- let stage: number | undefined = 1;
+export const updateMomentCategories =
+ (
+ categories: string[],
+ add: boolean,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ let success = false;
+ let stage: number | undefined = 1;
- stage = await postMomentCategories(categories, token);
- success = stage ? true : false;
- if (success) {
- dispatch({
- type: momentCategoriesFetched.type,
- payload: {categories},
- });
- if (add) {
+ stage = await postMomentCategories(categories, token);
+ success = stage ? true : false;
+ if (success) {
dispatch({
- type: profileCompletionStageUpdated.type,
- payload: {stage},
+ type: momentCategoriesFetched.type,
+ payload: {categories},
});
+ if (add) {
+ dispatch({
+ type: profileCompletionStageUpdated.type,
+ payload: {stage},
+ });
+ }
}
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
diff --git a/src/store/actions/notifications.ts b/src/store/actions/notifications.ts
index bace1776..88a1cf94 100644
--- a/src/store/actions/notifications.ts
+++ b/src/store/actions/notifications.ts
@@ -3,19 +3,16 @@ import {getNotificationsData} from '../../services';
import {userNotificationsFetched} from '../reducers';
import {RootState} from '../rootReducer';
-export const loadUserNotifications = (): ThunkAction<
- Promise<void>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- try {
- const notifications = await getNotificationsData();
- dispatch({
- type: userNotificationsFetched.type,
- payload: notifications,
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadUserNotifications =
+ (): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const notifications = await getNotificationsData();
+ dispatch({
+ type: userNotificationsFetched.type,
+ payload: notifications,
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
diff --git a/src/store/actions/socials.ts b/src/store/actions/socials.ts
index f79b4ad1..1824ca53 100644
--- a/src/store/actions/socials.ts
+++ b/src/store/actions/socials.ts
@@ -4,35 +4,35 @@ import {Action, ThunkAction} from '@reduxjs/toolkit';
import {userSocialsFetched, individualSocialfetched} from '../reducers';
import {loadAllSocialsForUser} from '../../utils';
-export const loadIndividualSocial = (
- userId: string,
- socialType: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const social = await loadSocialPosts(userId, socialType);
- dispatch({
- type: individualSocialfetched.type,
- payload: {socialType, social},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadIndividualSocial =
+ (
+ userId: string,
+ socialType: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const social = await loadSocialPosts(userId, socialType);
+ dispatch({
+ type: individualSocialfetched.type,
+ payload: {socialType, social},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const loadAllSocials = (
- userId: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const socials = await loadAllSocialsForUser(userId);
- dispatch({
- type: userSocialsFetched.type,
- payload: socials,
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadAllSocials =
+ (
+ userId: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const socials = await loadAllSocialsForUser(userId);
+ dispatch({
+ type: userSocialsFetched.type,
+ payload: socials,
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
diff --git a/src/store/actions/taggUsers.ts b/src/store/actions/taggUsers.ts
index 0cd94e92..bcb39cc5 100644
--- a/src/store/actions/taggUsers.ts
+++ b/src/store/actions/taggUsers.ts
@@ -3,19 +3,16 @@ import {loadRecentlySearchedUsers} from '../../services';
import {taggUsersFetched} from '../reducers';
import {RootState} from '../rootReducer';
-export const loadRecentlySearched = (): ThunkAction<
- Promise<void>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- try {
- const recentSearches = await loadRecentlySearchedUsers();
- dispatch({
- type: taggUsersFetched.type,
- payload: {recentSearches},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadRecentlySearched =
+ (): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const recentSearches = await loadRecentlySearchedUsers();
+ dispatch({
+ type: taggUsersFetched.type,
+ payload: {recentSearches},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts
index 96e636f6..941101df 100644
--- a/src/store/actions/user.ts
+++ b/src/store/actions/user.ts
@@ -36,220 +36,219 @@ import {CommentThreadType} from './../../types/types';
* https://github.com/reduxjs/redux-thunk
*/
-export const loadUserData = (
- user: UserType,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- await dispatch({type: userLoggedIn.type, payload: user});
- const token = await getTokenOrLogout(dispatch);
- const [profile, avatar, cover] = await Promise.all([
- loadProfileInfo(token, user.userId),
- getProfilePic(token, user.userId, 'profile'),
- getProfilePic(token, user.userId, 'header'),
- ]);
- dispatch({
- type: userDetailsFetched.type,
- payload: {profile, cover, avatar},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadUserData =
+ (
+ user: UserType,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ await dispatch({type: userLoggedIn.type, payload: user});
+ const token = await getTokenOrLogout(dispatch);
+ const [profile, avatar, cover] = await Promise.all([
+ loadProfileInfo(token, user.userId),
+ getProfilePic(token, user.userId, 'profile'),
+ getProfilePic(token, user.userId, 'header'),
+ ]);
+ dispatch({
+ type: userDetailsFetched.type,
+ payload: {profile, cover, avatar},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const resetHeaderAndProfileImage = (): ThunkAction<
- Promise<void>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- await dispatch({
- type: clearHeaderAndProfileImages.type,
- payload: {},
- });
-};
+export const resetHeaderAndProfileImage =
+ (): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ await dispatch({
+ type: clearHeaderAndProfileImages.type,
+ payload: {},
+ });
+ };
/**
* To update editable socials
* @param social social to be updated
* @param value username of social to be updated
*/
-export const updateSocial = (
- social: string,
- value: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: socialEdited.type,
- payload: {social, value},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateSocial =
+ (
+ social: string,
+ value: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: socialEdited.type,
+ payload: {social, value},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
/**
* To update new user badges
* @param badges current selection of badges
*/
-export const updateUserBadges = (
- badges: UniversityBadge[],
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: profileBadgesUpdated.type,
- payload: {badges},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateUserBadges =
+ (
+ badges: UniversityBadge[],
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: profileBadgesUpdated.type,
+ payload: {badges},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateProfileCompletionStage = (
- stage: number,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: profileCompletionStageUpdated.type,
- payload: {stage},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateProfileCompletionStage =
+ (
+ stage: number,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: profileCompletionStageUpdated.type,
+ payload: {stage},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateIsOnboardedUser = (
- isOnboardedUser: boolean,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: setIsOnboardedUser.type,
- payload: {isOnboardedUser},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateIsOnboardedUser =
+ (
+ isOnboardedUser: boolean,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: setIsOnboardedUser.type,
+ payload: {isOnboardedUser},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateNewVersionAvailable = (
- newVersionAvailable: boolean,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: setNewVersionAvailable.type,
- payload: {newVersionAvailable},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateNewVersionAvailable =
+ (
+ newVersionAvailable: boolean,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: setNewVersionAvailable.type,
+ payload: {newVersionAvailable},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateNewNotificationReceived = (
- newNotificationReceived: boolean,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: setNewNotificationReceived.type,
- payload: {newNotificationReceived},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateNewNotificationReceived =
+ (
+ newNotificationReceived: boolean,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: setNewNotificationReceived.type,
+ payload: {newNotificationReceived},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-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 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 = (
- client?: StreamChat,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- // do our best effort here to gracefully disconnect the user
- if (client) {
- client.disconnectUser();
+export const logout =
+ (
+ client?: StreamChat,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ // do our best effort here to gracefully disconnect the user
+ if (client) {
+ client.disconnectUser();
+ }
+ await AsyncStorage.clear();
+ dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}});
+ } catch (error) {
+ console.log(error);
}
- await AsyncStorage.clear();
- dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}});
- } catch (error) {
- console.log(error);
- }
-};
+ };
-export const uploadedSuggestedPeoplePhoto = (
- imageUri: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- await dispatch({
- type: setSuggestedPeopleImage.type,
- payload: {suggestedPeopleImage: imageUri},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const uploadedSuggestedPeoplePhoto =
+ (
+ imageUri: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ await dispatch({
+ type: setSuggestedPeopleImage.type,
+ payload: {suggestedPeopleImage: imageUri},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const suggestedPeopleBadgesFinished = (): ThunkAction<
- Promise<void>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- try {
- dispatch({
- type: setSuggestedPeopleLinked.type,
- payload: {suggested_people_linked: 1},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const suggestedPeopleBadgesFinished =
+ (): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: setSuggestedPeopleLinked.type,
+ payload: {suggested_people_linked: 1},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const suggestedPeopleAnimatedTutorialFinished = (
- userId: string,
-): ThunkAction<
- Promise<boolean | undefined>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- try {
- // update store first, assume request is successful
- dispatch({
- type: setSuggestedPeopleLinked.type,
- payload: {suggested_people_linked: 2},
- });
- // need to tell the server that the stage is now 2
- return await sendSuggestedPeopleLinked(userId, 2);
- } catch (error) {
- console.log('Error while updating suggested people linked state: ', error);
- }
-};
+export const suggestedPeopleAnimatedTutorialFinished =
+ (
+ userId: string,
+ ): ThunkAction<
+ Promise<boolean | undefined>,
+ RootState,
+ unknown,
+ Action<string>
+ > =>
+ async (dispatch) => {
+ try {
+ // update store first, assume request is successful
+ dispatch({
+ type: setSuggestedPeopleLinked.type,
+ payload: {suggested_people_linked: 2},
+ });
+ // need to tell the server that the stage is now 2
+ return await sendSuggestedPeopleLinked(userId, 2);
+ } catch (error) {
+ console.log(
+ 'Error while updating suggested people linked state: ',
+ error,
+ );
+ }
+ };
diff --git a/src/store/actions/userBlock.ts b/src/store/actions/userBlock.ts
index be6f9331..82796682 100644
--- a/src/store/actions/userBlock.ts
+++ b/src/store/actions/userBlock.ts
@@ -5,44 +5,44 @@ import {getTokenOrLogout} from '../../utils';
import {updateBlockedList, userBlockFetched} from '../reducers';
import {RootState} from '../rootReducer';
-export const loadBlockedList = (
- userId: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const blocked = await loadBlockedUsers(userId, token);
- dispatch({
- type: userBlockFetched.type,
- payload: blocked,
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadBlockedList =
+ (
+ userId: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const blocked = await loadBlockedUsers(userId, token);
+ dispatch({
+ type: userBlockFetched.type,
+ payload: blocked,
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const blockUnblockUser = (
- blocker: UserType,
- blocked: ProfilePreviewType,
- isBlocked: boolean,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- const token = await getTokenOrLogout(dispatch);
- const success = blockOrUnblockUser(
- blocker.userId,
- blocked.id,
- token,
- isBlocked,
- );
- if (success) {
- dispatch({
- type: updateBlockedList.type,
- payload: {
- isBlocked,
- data: blocked,
- },
- });
- }
-};
+export const blockUnblockUser =
+ (
+ blocker: UserType,
+ blocked: ProfilePreviewType,
+ isBlocked: boolean,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ const token = await getTokenOrLogout(dispatch);
+ const success = blockOrUnblockUser(
+ blocker.userId,
+ blocked.id,
+ token,
+ isBlocked,
+ );
+ if (success) {
+ dispatch({
+ type: updateBlockedList.type,
+ payload: {
+ isBlocked,
+ data: blocked,
+ },
+ });
+ }
+ };
diff --git a/src/store/actions/userFriends.ts b/src/store/actions/userFriends.ts
index 4183d0f6..07dab544 100644
--- a/src/store/actions/userFriends.ts
+++ b/src/store/actions/userFriends.ts
@@ -20,196 +20,198 @@ import {
} from '../reducers';
import {RootState} from '../rootReducer';
-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 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, //logged in user
+ friend: ProfilePreviewType, // userX's profile preview
+ friendship_status: FriendshipStatusType, // friendshp status with userx
+ screenType: ScreenType, //screentype from content
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ // Calls method to send post or delete request
+ const success = await friendOrUnfriendUser(
+ friend.id,
+ token,
+ friendship_status,
+ );
+ if (success) {
+ let data = 'no_record';
+ switch (friendship_status) {
+ case 'no_record': // send request: update to requested
+ data = 'requested';
+ break;
+ case 'requested': // cancel request: update to no relationship
+ break;
+ case 'friends': // unfriend: update to no relationship
+ dispatch({
+ type: updateFriends.type,
+ payload: {
+ data: friend,
+ isFriend: true,
+ },
+ });
+ data = 'no_record';
+ break;
+ }
+ dispatch({
+ type: userXFriendshipEdited.type,
+ payload: {
+ userId: friend.id,
+ screenType,
+ data,
+ },
+ });
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const friendUnfriendUser = (
- user: UserType, //logged in user
- friend: ProfilePreviewType, // userX's profile preview
- friendship_status: FriendshipStatusType, // friendshp status with userx
- screenType: ScreenType, //screentype from content
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- // Calls method to send post or delete request
- const success = await friendOrUnfriendUser(
- friend.id,
- token,
- friendship_status,
- );
- if (success) {
- let data = 'no_record';
- switch (friendship_status) {
- case 'no_record': // send request: update to requested
- data = 'requested';
- break;
- case 'requested': // cancel request: update to no relationship
- break;
- case 'friends': // unfriend: update to no relationship
+export const addFriend =
+ (
+ friend: ProfilePreviewType, // userX's profile preview
+ screenType: ScreenType, //screentype from content
+ state: RootState,
+ ): ThunkAction<
+ Promise<boolean | undefined>,
+ RootState,
+ unknown,
+ Action<string>
+ > =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const success = await addFriendService(friend.id, token);
+ if (success) {
+ if (userXInStore(state, screenType, friend.id)) {
dispatch({
- type: updateFriends.type,
+ type: userXFriendshipEdited.type,
payload: {
- data: friend,
- isFriend: true,
+ userId: friend.id,
+ screen: screenType,
+ data: 'requested',
},
});
- data = 'no_record';
- break;
+ }
+ return true;
}
- dispatch({
- type: userXFriendshipEdited.type,
- payload: {
- userId: friend.id,
- screenType,
- data,
- },
- });
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
-export const addFriend = (
- friend: ProfilePreviewType, // userX's profile preview
- screenType: ScreenType, //screentype from content
- state: RootState,
-): ThunkAction<
- Promise<boolean | undefined>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const success = await addFriendService(friend.id, token);
- if (success) {
- if (userXInStore(state, screenType, friend.id)) {
- dispatch({
+export const unfriendUser =
+ (
+ friend: ProfilePreviewType, // userX's profile preview
+ screenType: ScreenType, //screentype from content
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ // Calls method to send post or delete request
+ const reason = 'unfriended';
+ const success = await deleteFriendshipService(friend.id, reason, token);
+ if (success) {
+ let data = 'no_record';
+ await dispatch({
+ type: updateFriends.type,
+ payload: {
+ data: friend,
+ isFriend: true,
+ },
+ });
+ await dispatch({
type: userXFriendshipEdited.type,
payload: {
userId: friend.id,
- screen: screenType,
- data: 'requested',
+ screenType,
+ data,
},
});
}
- return true;
- }
- } catch (error) {
- console.log(error);
- }
-};
-
-export const unfriendUser = (
- friend: ProfilePreviewType, // userX's profile preview
- screenType: ScreenType, //screentype from content
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- // Calls method to send post or delete request
- const reason = 'unfriended';
- const success = await deleteFriendshipService(friend.id, reason, token);
- if (success) {
- let data = 'no_record';
- await dispatch({
- type: updateFriends.type,
- payload: {
- data: friend,
- isFriend: true,
- },
- });
- await dispatch({
- type: userXFriendshipEdited.type,
- payload: {
- userId: friend.id,
- screenType,
- data,
- },
- });
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
-export const acceptFriendRequest = (
- requester: ProfilePreviewType,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const success = await acceptFriendRequestService(requester.id, token);
- if (success) {
- dispatch({
- type: updateFriends.type,
- payload: {
- data: requester,
- isFriend: false,
- },
- });
+export const acceptFriendRequest =
+ (
+ requester: ProfilePreviewType,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const success = await acceptFriendRequestService(requester.id, token);
+ if (success) {
+ dispatch({
+ type: updateFriends.type,
+ payload: {
+ data: requester,
+ isFriend: false,
+ },
+ });
+ }
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
-export const declineFriendRequest = (
- user_id: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const reason = 'declined';
- const success = await deleteFriendshipService(user_id, reason, token);
- if (success) {
- // Get profile of requester
- console.log('declined request: ', success);
- } else {
- console.log('Unsuccessful call');
+export const declineFriendRequest =
+ (
+ user_id: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const reason = 'declined';
+ const success = await deleteFriendshipService(user_id, reason, token);
+ if (success) {
+ // Get profile of requester
+ console.log('declined request: ', success);
+ } else {
+ console.log('Unsuccessful call');
+ }
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
-export const cancelFriendRequest = (
- user_id: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- console.log('cancelFriendRequest!');
- const token = await getTokenOrLogout(dispatch);
- const reason = 'cancelled';
- const success = await deleteFriendshipService(user_id, reason, token);
- if (success) {
- // Get profile of requester
- console.log('cancelled request: ', success);
- } else {
- console.log('Unsuccessful call');
+export const cancelFriendRequest =
+ (
+ user_id: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ console.log('cancelFriendRequest!');
+ const token = await getTokenOrLogout(dispatch);
+ const reason = 'cancelled';
+ const success = await deleteFriendshipService(user_id, reason, token);
+ if (success) {
+ // Get profile of requester
+ console.log('cancelled request: ', success);
+ } else {
+ console.log('Unsuccessful call');
+ }
+ } catch (error) {
+ console.log(error);
}
- } catch (error) {
- console.log(error);
- }
-};
+ };
diff --git a/src/store/actions/userMoments.ts b/src/store/actions/userMoments.ts
index 4d739129..23cd09ac 100644
--- a/src/store/actions/userMoments.ts
+++ b/src/store/actions/userMoments.ts
@@ -4,34 +4,34 @@ import {Action, ThunkAction} from '@reduxjs/toolkit';
import {userMomentsFetched, momentCategoryDeleted} from '../reducers';
import {getTokenOrLogout} from '../../utils';
-export const loadUserMoments = (
- userId: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const token = await getTokenOrLogout(dispatch);
- const moments = await loadMoments(userId, token);
- dispatch({
- type: userMomentsFetched.type,
- payload: moments,
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const loadUserMoments =
+ (
+ userId: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const token = await getTokenOrLogout(dispatch);
+ const moments = await loadMoments(userId, token);
+ dispatch({
+ type: userMomentsFetched.type,
+ payload: moments,
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const deleteUserMomentsForCategory = (
- category: string,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: momentCategoryDeleted.type,
- payload: category,
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const deleteUserMomentsForCategory =
+ (
+ category: string,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: momentCategoryDeleted.type,
+ payload: category,
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts
index f32a4d8f..855aaeaf 100644
--- a/src/store/actions/userX.ts
+++ b/src/store/actions/userX.ts
@@ -23,138 +23,141 @@ import {RootState} from '../rootReducer';
import {getTokenOrLogout, loadAllSocialsForUser} from './../../utils';
import {userXInStore} from './../../utils/';
-export const loadUserX = (
- user: UserType,
- screenType: ScreenType,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- 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);
- 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'),
+export const loadUserX =
+ (
+ user: UserType,
+ screenType: ScreenType,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ 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);
+ 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, token).then((data) =>
dispatch({
- type: userXAvatarFetched.type,
- payload: {screenType, userId, data: profile.profile_pic},
- });
+ type: userXSocialsFetched.type,
+ payload: {screenType, userId, data},
+ }),
+ );
+ loadFriends(userId, token).then((data) =>
dispatch({
- type: userXCoverFetched.type,
- payload: {screenType, userId, data: profile.header_pic},
- });
+ type: userXFriendsFetched.type,
+ payload: {screenType, userId, data},
+ }),
+ );
+ loadMoments(userId, token).then((data) =>
dispatch({
- type: userXMomentCategoriesFetched.type,
- payload: {screenType, userId, data: profile.moment_categories},
- });
- }
- });
- loadAllSocialsForUser(userId, token).then((data) =>
- dispatch({
- type: userXSocialsFetched.type,
- payload: {screenType, userId, data},
- }),
- );
- loadFriends(userId, token).then((data) =>
- dispatch({
- type: userXFriendsFetched.type,
- payload: {screenType, userId, data},
- }),
- );
- loadMoments(userId, token).then((data) =>
- dispatch({
- type: userXMomentsFetched.type,
- payload: {screenType, userId, data},
- }),
- );
- } catch (error) {
- console.log(error);
- }
-};
+ type: userXMomentsFetched.type,
+ payload: {screenType, userId, data},
+ }),
+ );
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateUserXFriends = (
- userId: string,
- state: RootState,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const screens = <ScreenType[]>[
- ScreenType.Profile,
- ScreenType.Search,
- ScreenType.Notifications,
- ];
- const token = await getTokenOrLogout(dispatch);
- screens.forEach((screenType) => {
- if (userXInStore(state, screenType, userId)) {
- loadFriends(userId, token).then((data) =>
- dispatch({
- type: userXFriendsFetched.type,
- payload: {screenType, userId, data},
- }),
- );
- }
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const updateUserXFriends =
+ (
+ userId: string,
+ state: RootState,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const screens = <ScreenType[]>[
+ ScreenType.Profile,
+ ScreenType.Search,
+ ScreenType.Notifications,
+ ];
+ const token = await getTokenOrLogout(dispatch);
+ screens.forEach((screenType) => {
+ if (userXInStore(state, screenType, userId)) {
+ loadFriends(userId, token).then((data) =>
+ dispatch({
+ type: userXFriendsFetched.type,
+ payload: {screenType, userId, data},
+ }),
+ );
+ }
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const resetScreenType = (
- screenType: ScreenType,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- dispatch({
- type: resetScreen.type,
- payload: {screenType},
- });
- } catch (error) {
- console.log(error);
- }
-};
+export const resetScreenType =
+ (
+ screenType: ScreenType,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ dispatch({
+ type: resetScreen.type,
+ payload: {screenType},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
-export const updateUserXProfileAllScreens = (
- userId: string,
- state: RootState,
-): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
- dispatch,
-) => {
- try {
- const screens = <ScreenType[]>[
- ScreenType.Profile,
- ScreenType.Search,
- ScreenType.Notifications,
- ];
- const token = await getTokenOrLogout(dispatch);
- screens.forEach((screenType) => {
- if (userXInStore(state, screenType, userId)) {
- loadProfileInfo(token, userId).then((data) => {
- dispatch({
- type: userXProfileFetched.type,
- payload: {screenType, userId, data},
+export const updateUserXProfileAllScreens =
+ (
+ userId: string,
+ state: RootState,
+ ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> =>
+ async (dispatch) => {
+ try {
+ const screens = <ScreenType[]>[
+ ScreenType.Profile,
+ ScreenType.Search,
+ ScreenType.Notifications,
+ ];
+ const token = await getTokenOrLogout(dispatch);
+ screens.forEach((screenType) => {
+ if (userXInStore(state, screenType, userId)) {
+ loadProfileInfo(token, userId).then((data) => {
+ dispatch({
+ type: userXProfileFetched.type,
+ payload: {screenType, userId, data},
+ });
});
- });
- }
- });
- } catch (error) {
- console.log(error);
- }
-};
+ }
+ });
+ } catch (error) {
+ console.log(error);
+ }
+ };
diff --git a/src/store/reducers/userMomentsReducer.ts b/src/store/reducers/userMomentsReducer.ts
index 97c9a1fd..e1e8d96c 100644
--- a/src/store/reducers/userMomentsReducer.ts
+++ b/src/store/reducers/userMomentsReducer.ts
@@ -18,8 +18,6 @@ const userMomentsSlice = createSlice({
},
});
-export const {
- userMomentsFetched,
- momentCategoryDeleted,
-} = userMomentsSlice.actions;
+export const {userMomentsFetched, momentCategoryDeleted} =
+ userMomentsSlice.actions;
export const userMomentsReducer = userMomentsSlice.reducer;
diff --git a/src/store/reducers/userSocialsReducer.ts b/src/store/reducers/userSocialsReducer.ts
index de79568c..1186fa80 100644
--- a/src/store/reducers/userSocialsReducer.ts
+++ b/src/store/reducers/userSocialsReducer.ts
@@ -14,8 +14,6 @@ const userSocialsSlice = createSlice({
},
});
-export const {
- userSocialsFetched,
- individualSocialfetched,
-} = userSocialsSlice.actions;
+export const {userSocialsFetched, individualSocialfetched} =
+ userSocialsSlice.actions;
export const userSocialsReducer = userSocialsSlice.reducer;
diff --git a/src/store/reducers/userXReducer.ts b/src/store/reducers/userXReducer.ts
index 9f90d58d..0a9e71bb 100644
--- a/src/store/reducers/userXReducer.ts
+++ b/src/store/reducers/userXReducer.ts
@@ -7,9 +7,8 @@ const userXSlice = createSlice({
initialState: EMPTY_SCREEN_TO_USERS_LIST,
reducers: {
userXRequested: (state, action) => {
- state[<ScreenType>action.payload.screenType][
- action.payload.userId
- ] = EMPTY_USER_X;
+ state[<ScreenType>action.payload.screenType][action.payload.userId] =
+ EMPTY_USER_X;
},
userXProfileFetched: (state, action) => {