mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 11:55:17 +02:00
Adding Categories and Bookmarks using form
This commit is contained in:
parent
38edb76929
commit
c145888aec
7 changed files with 116 additions and 13 deletions
|
@ -27,12 +27,40 @@ const getCategoriesSuccess = (state: State, action: Action): State => {
|
|||
loading: false,
|
||||
categories: action.payload
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const addCategory = (state: State, action: Action): State => {
|
||||
const tmpCategories = [...state.categories, {
|
||||
...action.payload,
|
||||
bookmarks: []
|
||||
}];
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: tmpCategories
|
||||
}
|
||||
}
|
||||
|
||||
const addBookmark = (state: State, action: Action): State => {
|
||||
const tmpCategories = [...state.categories];
|
||||
const tmpCategory = tmpCategories.find((category: Category) => category.id === action.payload.categoryId);
|
||||
|
||||
if (tmpCategory) {
|
||||
tmpCategory.bookmarks.push(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);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue