From 4a261cd82b1c356a9903e7db61ce451c18c1b52a Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Mon, 29 Jul 2019 12:02:27 +0300 Subject: [PATCH] catalogs hook provides raw data from the stte container --- src/routes/Board/Board.js | 30 ++++++++++++++++++++++-------- src/routes/Board/useCatalogs.js | 18 +----------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/routes/Board/Board.js b/src/routes/Board/Board.js index f0da1788a..cdb4027fd 100644 --- a/src/routes/Board/Board.js +++ b/src/routes/Board/Board.js @@ -21,14 +21,28 @@ const Board = () => {
- {catalogs.map((catalog) => ( - - ))} + { + catalogs + .filter(([_, response]) => response.type === 'Ready') + .map(([request, response]) => [ + request, + { + ...response, + content: response.content.map((item) => ({ + ...item, + posterShape: item.posterShape || 'poster' + })) + } + ]) + .map(([request, response], index) => ( + + )) + }
); diff --git a/src/routes/Board/useCatalogs.js b/src/routes/Board/useCatalogs.js index 9d4fb0183..e4d20d1d9 100644 --- a/src/routes/Board/useCatalogs.js +++ b/src/routes/Board/useCatalogs.js @@ -5,23 +5,7 @@ const useCatalogs = () => { React.useEffect(() => { const onNewState = () => { const state = window.stateContainer.getState(); - const catalogs = state.groups.reduce((catalogs, [request, response], index) => { - if (response.type === 'Ready') { - catalogs.push({ - id: `${index}${request.transport_url}`, - title: `${request.resource_ref.id} - ${request.resource_ref.type_name}`, - items: response.content.map((item) => { - return { - ...item, - posterShape: item.posterShape || 'poster' - }; - }) - }); - } - - return catalogs; - }, []); - setCatalogs(catalogs); + setCatalogs(state.groups); }; window.stateContainer.on('NewState', onNewState); window.stateContainer.dispatch({