Added in-session recent items with cross tab support. BOD-178
This commit is contained in:
@@ -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)];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user