aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2021-01-12 12:38:46 -0500
committerGitHub <noreply@github.com>2021-01-12 12:38:46 -0500
commit6892c63b899b46fedc9d99b8274a17e9043fe361 (patch)
tree454d836c5848b4d9b2e082ae19e4e64679ccd49d /src/store
parentd955c6bc31be3b2e3e289a8dec8b5970251d4090 (diff)
[TMA-527/506/523] Custom Moment Categories (#174)
* changed logic to allow ≥ 1 categories * now using array of strings for moment categories * updated error strings * formatting and check for picker cancellation * initial UI done * cleaned up logic, added custom icon * renamed onboarding stack to match main stack * removed unused import * deterministic color picker * custom category defaults to selected instead of added * removed function in route
Diffstat (limited to 'src/store')
-rw-r--r--src/store/actions/momentCategories.tsx23
-rw-r--r--src/store/initialStates.ts23
-rw-r--r--src/store/reducers/momentCategoryReducer.tsx9
-rw-r--r--src/store/reducers/userXReducer.ts12
4 files changed, 16 insertions, 51 deletions
diff --git a/src/store/actions/momentCategories.tsx b/src/store/actions/momentCategories.tsx
index a522c3e0..987fc9e5 100644
--- a/src/store/actions/momentCategories.tsx
+++ b/src/store/actions/momentCategories.tsx
@@ -1,13 +1,8 @@
import {RootState} from '../rootReducer';
-import {
- deleteMomentCategories,
- loadMomentCategories,
- postMomentCategories,
-} from '../../services';
+import {loadMomentCategories, postMomentCategories} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
import {momentCategoriesFetched} from '../reducers';
import {getTokenOrLogout} from '../../utils';
-import {MomentCategoryType} from '../../types';
/**
* Load all categories for user
@@ -23,7 +18,7 @@ export const loadUserMomentCategories = (
const categories = await loadMomentCategories(userId, token);
dispatch({
type: momentCategoriesFetched.type,
- payload: {categories, add: true},
+ payload: {categories},
});
} catch (error) {
console.log(error);
@@ -33,28 +28,20 @@ export const loadUserMomentCategories = (
/**
* Handle addition / deletion of categories for a user
* @param categories List of categories
- * @param add boolean, if true, we add new categories, else we delete
* @param userId id of the user for whom categories should be updated
*/
export const updateMomentCategories = (
- categories: Array<MomentCategoryType>,
- add: boolean,
- userId: string,
+ categories: string[],
): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
dispatch,
) => {
try {
const token = await getTokenOrLogout(dispatch);
- let success = false;
- if (add) {
- success = await postMomentCategories(categories, token);
- } else {
- success = await deleteMomentCategories(categories, userId, token);
- }
+ const success = await postMomentCategories(categories, token);
if (success) {
dispatch({
type: momentCategoriesFetched.type,
- payload: {categories, add},
+ payload: {categories},
});
}
} catch (error) {
diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts
index da3ef3b0..09607758 100644
--- a/src/store/initialStates.ts
+++ b/src/store/initialStates.ts
@@ -1,5 +1,4 @@
import {
- MomentCategoryType,
MomentType,
NotificationType,
ProfilePreviewType,
@@ -70,23 +69,7 @@ export const NO_BLOCKED_USERS = {
blockedUsers: EMPTY_PROFILE_PREVIEW_LIST,
};
-export const MOMENT_CATEGORIES_MAP: Record<MomentCategoryType, boolean> = {
- Friends: false,
- Adventure: false,
- 'Photo Dump': false,
- Food: false,
- Music: false,
- Art: false,
- Sports: false,
- Fashion: false,
- Travel: false,
- Pets: false,
- Fitness: false,
- DIY: false,
- Nature: false,
- 'Early Life': false,
- Beauty: false,
-};
+export const EMPTY_MOMENT_CATEGORIES: string[] = [];
/**
* The dummy userId and username serve the purpose of preventing app crash
@@ -99,7 +82,7 @@ export const DUMMY_USERNAME = 'tagg_userX';
export const EMPTY_USER_X = <UserXType>{
friends: EMPTY_PROFILE_PREVIEW_LIST,
moments: EMPTY_MOMENTS_LIST,
- momentCategories: MOMENT_CATEGORIES_MAP,
+ momentCategories: EMPTY_MOMENT_CATEGORIES,
socialAccounts: NO_SOCIAL_ACCOUNTS,
user: NO_USER,
profile: NO_PROFILE,
@@ -124,5 +107,5 @@ export const EMPTY_SCREEN_TO_USERS_LIST: Record<
};
export const INITIAL_CATEGORIES_STATE = {
- momentCategories: MOMENT_CATEGORIES_MAP,
+ momentCategories: EMPTY_MOMENT_CATEGORIES,
};
diff --git a/src/store/reducers/momentCategoryReducer.tsx b/src/store/reducers/momentCategoryReducer.tsx
index d1f448f9..b6909b87 100644
--- a/src/store/reducers/momentCategoryReducer.tsx
+++ b/src/store/reducers/momentCategoryReducer.tsx
@@ -1,19 +1,16 @@
import {createSlice} from '@reduxjs/toolkit';
import {INITIAL_CATEGORIES_STATE} from '../initialStates';
-import {MomentCategoryType} from '../../types';
const momentCategoriesSlice = createSlice({
name: 'momentCategories',
initialState: INITIAL_CATEGORIES_STATE,
reducers: {
/**
- * One stop to add / delete / update categories for a user
+ * Replace a new copy of moment categories for a user
*/
momentCategoriesFetched: (state, action) => {
- const categories: Array<MomentCategoryType> = action.payload.categories;
- for (let category of categories) {
- state.momentCategories[category] = action.payload.add;
- }
+ const categories: string[] = action.payload.categories;
+ state.momentCategories = categories;
},
},
});
diff --git a/src/store/reducers/userXReducer.ts b/src/store/reducers/userXReducer.ts
index fa1598b2..3b00cf88 100644
--- a/src/store/reducers/userXReducer.ts
+++ b/src/store/reducers/userXReducer.ts
@@ -1,4 +1,4 @@
-import {MomentCategoryType, ScreenType} from '../../types/types';
+import {ScreenType} from '../../types/types';
import {EMPTY_SCREEN_TO_USERS_LIST, EMPTY_USER_X} from '../initialStates';
import {createSlice} from '@reduxjs/toolkit';
@@ -24,12 +24,10 @@ const userXSlice = createSlice({
},
userXMomentCategoriesFetched: (state, action) => {
- const categories: Array<MomentCategoryType> = action.payload.data;
- for (let category of categories) {
- state[<ScreenType>action.payload.screenType][
- action.payload.userId
- ].momentCategories[category] = true;
- }
+ const categories: string[] = action.payload.data;
+ state[<ScreenType>action.payload.screenType][
+ action.payload.userId
+ ].momentCategories = categories;
},
userXMomentsFetched: (state, action) => {