catalogs hook provides raw data from the stte container

This commit is contained in:
NikolaBorislavovHristov 2019-07-29 12:02:27 +03:00
parent 8fa98feab4
commit 4a261cd82b
2 changed files with 23 additions and 25 deletions

View file

@ -21,14 +21,28 @@ const Board = () => {
<div className={styles['board-container']}>
<MainNavBar className={styles['nav-bar']} />
<div className={styles['board-content']} tabIndex={-1}>
{catalogs.map((catalog) => (
<BoardRow
key={catalog.id}
className={styles['addon-catalog-row']}
title={catalog.title}
items={catalog.items}
/>
))}
{
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) => (
<BoardRow
key={`${index}${request.transport_url}`}
className={styles['addon-catalog-row']}
title={`${request.resource_ref.id} - ${request.resource_ref.type_name}`}
items={response.content}
/>
))
}
</div>
</div>
);

View file

@ -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({