From 01f3df880f370f567788523c63a56e0f94db590d Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Fri, 4 Aug 2023 16:11:19 -0400 Subject: [PATCH] STCOR-725 correctly load multiple icons per app Correctly handle multiple icons per application. Refs STCOR-725 --- src/okapiReducer.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/okapiReducer.js b/src/okapiReducer.js index 785e3b484..0c197abd3 100644 --- a/src/okapiReducer.js +++ b/src/okapiReducer.js @@ -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;