mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 03:35:18 +02:00
Pin/Delete category
This commit is contained in:
parent
bd5354a2e3
commit
0f2125e720
8 changed files with 156 additions and 7 deletions
|
@ -55,12 +55,37 @@ const addBookmark = (state: State, action: Action): State => {
|
|||
}
|
||||
}
|
||||
|
||||
const pinCategory = (state: State, action: Action): State => {
|
||||
const tmpCategories = [...state.categories];
|
||||
const changedCategory = tmpCategories.find((category: Category) => category.id === action.payload.id);
|
||||
|
||||
if (changedCategory) {
|
||||
changedCategory.isPinned = action.payload.isPinned;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: tmpCategories
|
||||
}
|
||||
}
|
||||
|
||||
const deleteCategory = (state: State, action: Action): State => {
|
||||
const tmpCategories = [...state.categories].filter((category: Category) => category.id !== action.payload);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: tmpCategories
|
||||
}
|
||||
}
|
||||
|
||||
const bookmarkReducer = (state = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case ActionTypes.getCategories: return getCategories(state, action);
|
||||
case ActionTypes.getCategoriesSuccess: return getCategoriesSuccess(state, action);
|
||||
case ActionTypes.addCategory: return addCategory(state, action);
|
||||
case ActionTypes.addBookmark: return addBookmark(state, action);
|
||||
case ActionTypes.pinCategory: return pinCategory(state, action);
|
||||
case ActionTypes.deleteCategory: return deleteCategory(state, action);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue