Skip to content

Commit

Permalink
STCOR-725 correctly load multiple icons per app
Browse files Browse the repository at this point in the history
Correctly handle multiple icons per application.

Refs STCOR-725
  • Loading branch information
zburke committed Aug 4, 2023
1 parent fe2e4fb commit 01f3df8
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/okapiReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,33 @@ export default function okapiReducer(state = {}, action) {
case 'UPDATE_CURRENT_USER':
return { ...state, currentUser: { ...state.currentUser, ...action.data } };

case 'ADD_ICON':
return { ...state, icons: { ...state.icons, [action.key]: action.icon } };
/**
* state.icons looks like
* {
* "@folio/some-app": {
* app: { alt, src},
* otherIcon: { alt, src }
* },
* "@folio/other-app": { app: ...}
* }
*
* action.key looks like @folio/some-app or @folio/other-app
* action.icon looks like { alt: ... } or { otherIcon: ... }
*/
case 'ADD_ICON': {
let val = action.icon;

// if there are already icons defined for this key,
// add this payload to them
if (state.icons?.[action.key]) {
val = {
...state.icons[action.key],
...action.icon,
};
}

return { ...state, icons: { ...state.icons, [action.key]: val } };
}

default:
return state;
Expand Down

0 comments on commit 01f3df8

Please sign in to comment.