mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 11:55:17 +02:00
Fixed bug with alphabetical order not working for bookmarks. Minor changes related to bookmarks form
This commit is contained in:
parent
ec5f50aba4
commit
d5610ad6be
12 changed files with 89 additions and 17 deletions
|
@ -23,6 +23,7 @@ import {
|
|||
ReorderCategoriesAction,
|
||||
SetEditBookmarkAction,
|
||||
SetEditCategoryAction,
|
||||
SortBookmarksAction,
|
||||
SortCategoriesAction,
|
||||
UpdateBookmarkAction,
|
||||
UpdateCategoryAction,
|
||||
|
@ -100,6 +101,8 @@ export const addBookmark =
|
|||
type: ActionType.addBookmark,
|
||||
payload: res.data.data,
|
||||
});
|
||||
|
||||
dispatch<any>(sortBookmarks(res.data.data.categoryId));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -271,6 +274,8 @@ export const updateBookmark =
|
|||
payload: res.data.data,
|
||||
});
|
||||
}
|
||||
|
||||
dispatch<any>(sortBookmarks(res.data.data.categoryId));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -377,3 +382,20 @@ export const reorderBookmarks =
|
|||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const sortBookmarks =
|
||||
(categoryId: number) => async (dispatch: Dispatch<SortBookmarksAction>) => {
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Config>>('/api/config');
|
||||
|
||||
dispatch({
|
||||
type: ActionType.sortBookmarks,
|
||||
payload: {
|
||||
orderType: res.data.data.useOrdering,
|
||||
categoryId,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -41,6 +41,7 @@ export enum ActionType {
|
|||
updateBookmark = 'UPDATE_BOOKMARK',
|
||||
setEditBookmark = 'SET_EDIT_BOOKMARK',
|
||||
reorderBookmarks = 'REORDER_BOOKMARKS',
|
||||
sortBookmarks = 'SORT_BOOKMARKS',
|
||||
// AUTH
|
||||
login = 'LOGIN',
|
||||
logout = 'LOGOUT',
|
||||
|
|
|
@ -74,3 +74,11 @@ export interface ReorderBookmarksAction {
|
|||
categoryId: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SortBookmarksAction {
|
||||
type: ActionType.sortBookmarks;
|
||||
payload: {
|
||||
orderType: string;
|
||||
categoryId: number;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import {
|
|||
SetEditCategoryAction,
|
||||
SetEditBookmarkAction,
|
||||
ReorderBookmarksAction,
|
||||
SortBookmarksAction,
|
||||
} from './bookmark';
|
||||
|
||||
import {
|
||||
|
@ -87,6 +88,7 @@ export type Action =
|
|||
| UpdateBookmarkAction
|
||||
| SetEditBookmarkAction
|
||||
| ReorderBookmarksAction
|
||||
| SortBookmarksAction
|
||||
// Auth
|
||||
| LoginAction
|
||||
| LogoutAction
|
||||
|
|
|
@ -216,6 +216,29 @@ export const bookmarksReducer = (
|
|||
};
|
||||
}
|
||||
|
||||
case ActionType.sortBookmarks: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
||||
const sortedBookmarks = sortData<Bookmark>(
|
||||
state.categories[categoryIdx].bookmarks,
|
||||
action.payload.orderType
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
{
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: sortedBookmarks,
|
||||
},
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue