Skip to content

Commit

Permalink
fix error message when doing an action from home page (#657)
Browse files Browse the repository at this point in the history
which calls analytics but itemsById were not set there.

NHUB-430
  • Loading branch information
petrjasek authored Nov 8, 2023
1 parent 5163435 commit 6b118c0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions assets/home/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {BOOKMARK_ITEMS, REMOVE_BOOKMARK} from '../wire/actions';
import {CLOSE_MODAL, MODAL_FORM_VALID, RENDER_MODAL, SET_USER} from '../actions';
import {modalReducer} from '../reducers';
import {topicsReducer} from '../topics/reducer';
import {IArticle} from 'interfaces';

export interface IPersonalizedDashboardsWithData {
dashboard_id?: string;
Expand All @@ -23,6 +24,7 @@ interface IState {
topics: Array<any>;
products: Array<any>;
itemsByCard: any;
itemsById: {[_id: string]: IArticle};
activeCard: any;
uiConfig: any;
userProducts: Array<any>;
Expand All @@ -34,6 +36,7 @@ const initialState: IState = {
topics: [],
products: [],
itemsByCard: {},
itemsById: {},
activeCard: null,
uiConfig: {},
userProducts: [],
Expand Down Expand Up @@ -106,8 +109,13 @@ export default function homeReducer(state: IState & any = initialState, action:
}

case SET_CARD_ITEMS: {
const itemsById = {...state.itemsById};

setItemsById(itemsById, action.payload.items);

return {
...state,
itemsById,
itemsByCard: {
...state.itemsByCard,
[action.payload.card]: action.payload.items,
Expand All @@ -116,8 +124,15 @@ export default function homeReducer(state: IState & any = initialState, action:
}

case SET_MULTIPLE_CARD_ITEMS: {
const itemsById = {...state.itemsById};

for (const card in action.payload) {
setItemsById(itemsById, action.payload[card]);
}

return {
...state,
itemsById,
itemsByCard: {
...state.itemsByCard,
...action.payload,
Expand All @@ -134,3 +149,9 @@ export default function homeReducer(state: IState & any = initialState, action:
return {...state, topics: topicsReducer(state.topics, action)};
}
}

function setItemsById(itemsById: IState['itemsById'], items: Array<IArticle>) {
items.forEach((item: IArticle) => {
itemsById[item._id] = item;
});
}

0 comments on commit 6b118c0

Please sign in to comment.