aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/profile/Content.tsx3
-rw-r--r--src/store/actions/userMoments.ts17
-rw-r--r--src/store/reducers/userMomentsReducer.ts12
3 files changed, 29 insertions, 3 deletions
diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx
index a4e4198c..60f18cc2 100644
--- a/src/components/profile/Content.tsx
+++ b/src/components/profile/Content.tsx
@@ -38,6 +38,7 @@ import {
loadFriendsData,
updateUserXFriends,
updateMomentCategories,
+ deleteUserMomentsForCategory,
} from '../../store/actions';
import {
NO_USER,
@@ -137,7 +138,6 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => {
map.set(moment_category, [imageObject]);
}
});
-
setImagesMap(map);
}, [moments]);
@@ -240,6 +240,7 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => {
dispatch(
updateMomentCategories([category], false, loggedInUser.userId),
);
+ dispatch(deleteUserMomentsForCategory(category));
},
},
],
diff --git a/src/store/actions/userMoments.ts b/src/store/actions/userMoments.ts
index dce8da8a..4d739129 100644
--- a/src/store/actions/userMoments.ts
+++ b/src/store/actions/userMoments.ts
@@ -1,7 +1,7 @@
import {RootState} from '../rootReducer';
import {loadMoments} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
-import {userMomentsFetched} from '../reducers';
+import {userMomentsFetched, momentCategoryDeleted} from '../reducers';
import {getTokenOrLogout} from '../../utils';
export const loadUserMoments = (
@@ -20,3 +20,18 @@ export const loadUserMoments = (
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/reducers/userMomentsReducer.ts b/src/store/reducers/userMomentsReducer.ts
index 456ca2fa..97c9a1fd 100644
--- a/src/store/reducers/userMomentsReducer.ts
+++ b/src/store/reducers/userMomentsReducer.ts
@@ -8,8 +8,18 @@ const userMomentsSlice = createSlice({
userMomentsFetched: (state, action) => {
state.moments = action.payload;
},
+
+ momentCategoryDeleted: (state, action) => {
+ const category = action.payload;
+ state.moments = state.moments.filter(
+ (moment) => moment.moment_category !== category,
+ );
+ },
},
});
-export const {userMomentsFetched} = userMomentsSlice.actions;
+export const {
+ userMomentsFetched,
+ momentCategoryDeleted,
+} = userMomentsSlice.actions;
export const userMomentsReducer = userMomentsSlice.reducer;