mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 03:35:18 +02:00
Update bookmark. Changes to CSS. Changes to WeatherJob
This commit is contained in:
parent
519b6d0746
commit
96aa1f7d69
11 changed files with 165 additions and 36 deletions
|
@ -218,13 +218,16 @@ export const deleteBookmark = (bookmarkId: number, categoryId: number) => async
|
|||
*/
|
||||
export interface UpdateBookmarkAction {
|
||||
type: ActionTypes.updateBookmark,
|
||||
payload: Bookmark
|
||||
payload: {
|
||||
bookmark: Bookmark,
|
||||
categoryWasChanged: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export const updateBookmark = (bookmarkId: number, formData: NewBookmark) => async (dispatch: Dispatch) => {
|
||||
export const updateBookmark = (bookmarkId: number, formData: NewBookmark, categoryWasChanged: boolean) => async (dispatch: Dispatch) => {
|
||||
try {
|
||||
const res = await axios.put<ApiResponse<Bookmark>>(`/api/bookmarks/${bookmarkId}`, formData);
|
||||
|
||||
|
||||
dispatch<CreateNotificationAction>({
|
||||
type: ActionTypes.createNotification,
|
||||
payload: {
|
||||
|
@ -235,7 +238,10 @@ export const updateBookmark = (bookmarkId: number, formData: NewBookmark) => asy
|
|||
|
||||
dispatch<UpdateBookmarkAction>({
|
||||
type: ActionTypes.updateBookmark,
|
||||
payload: res.data.data
|
||||
payload: {
|
||||
bookmark: res.data.data,
|
||||
categoryWasChanged
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
|
@ -107,8 +107,38 @@ const deleteBookmark = (state: State, action: Action): State => {
|
|||
}
|
||||
|
||||
const updateBookmark = (state: State, action: Action): State => {
|
||||
const { bookmark, categoryWasChanged } = action.payload;
|
||||
const tmpCategories = [...state.categories];
|
||||
|
||||
let categoryIndex = state.categories.findIndex((category: Category) => category.id === bookmark.categoryId);
|
||||
let bookmarkIndex = state.categories[categoryIndex].bookmarks.findIndex((bookmark: Bookmark) => bookmark.id === bookmark.id);
|
||||
|
||||
// if (categoryWasChanged) {
|
||||
// const categoryInUpdate = tmpCategories.find((category: Category) => category.id === bookmark.categoryId);
|
||||
|
||||
// if (categoryInUpdate) {
|
||||
// categoryInUpdate.bookmarks = categoryInUpdate.bookmarks.filter((_bookmark: Bookmark) => _bookmark.id === bookmark.id);
|
||||
// }
|
||||
|
||||
// console.log(categoryInUpdate);
|
||||
// }
|
||||
|
||||
return {
|
||||
...state
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIndex),
|
||||
{
|
||||
...state.categories[categoryIndex],
|
||||
bookmarks: [
|
||||
...state.categories[categoryIndex].bookmarks.slice(0, bookmarkIndex),
|
||||
{
|
||||
...bookmark
|
||||
},
|
||||
...state.categories[categoryIndex].bookmarks.slice(bookmarkIndex + 1)
|
||||
]
|
||||
},
|
||||
...state.categories.slice(categoryIndex + 1)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue