Added in-session recent items with cross tab support. BOD-178

This commit is contained in:
Patrick Fic
2020-07-13 09:55:24 -07:00
parent 613e4e9a23
commit 20f864cd43
18 changed files with 362 additions and 39 deletions

View File

@@ -16,7 +16,7 @@ const applicationReducer = (state = INITIAL_STATE, action) => {
case ApplicationActionTypes.ADD_RECENT_ITEM:
return {
...state,
recentItems: [action.payload, ...state.recentItems.slice(0, 9)],
recentItems: updateRecentItemsArray(state, action.payload),
};
case ApplicationActionTypes.SET_BREAD_CRUMBS:
return {
@@ -63,3 +63,18 @@ const applicationReducer = (state = INITIAL_STATE, action) => {
};
export default applicationReducer;
const updateRecentItemsArray = (state, newItem) => {
//Check to see if the new item is in the list.
const matchingIndex = state.recentItems.findIndex((i) => i.id === newItem.id);
if (matchingIndex >= 0) {
return [
newItem,
...state.recentItems.slice(0, matchingIndex),
...state.recentItems.slice(matchingIndex + 1, 9),
];
} else {
return [newItem, ...state.recentItems.slice(0, 9)];
}
};