mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-10 14:33:11 +08:00
Update bookmark. Changes to CSS. Changes to WeatherJob
This commit is contained in:
@@ -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)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user