Skip to content

Commit 01f3df8

Browse files
committed
STCOR-725 correctly load multiple icons per app
Correctly handle multiple icons per application. Refs STCOR-725
1 parent fe2e4fb commit 01f3df8

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/okapiReducer.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,33 @@ export default function okapiReducer(state = {}, action) {
4141
case 'UPDATE_CURRENT_USER':
4242
return { ...state, currentUser: { ...state.currentUser, ...action.data } };
4343

44-
case 'ADD_ICON':
45-
return { ...state, icons: { ...state.icons, [action.key]: action.icon } };
44+
/**
45+
* state.icons looks like
46+
* {
47+
* "@folio/some-app": {
48+
* app: { alt, src},
49+
* otherIcon: { alt, src }
50+
* },
51+
* "@folio/other-app": { app: ...}
52+
* }
53+
*
54+
* action.key looks like @folio/some-app or @folio/other-app
55+
* action.icon looks like { alt: ... } or { otherIcon: ... }
56+
*/
57+
case 'ADD_ICON': {
58+
let val = action.icon;
59+
60+
// if there are already icons defined for this key,
61+
// add this payload to them
62+
if (state.icons?.[action.key]) {
63+
val = {
64+
...state.icons[action.key],
65+
...action.icon,
66+
};
67+
}
68+
69+
return { ...state, icons: { ...state.icons, [action.key]: val } };
70+
}
4671

4772
default:
4873
return state;

0 commit comments

Comments
 (0)