From 65d30bc743b5293c2d53ab20fd846ce3cd28f6dd Mon Sep 17 00:00:00 2001 From: sepulzera Date: Sat, 19 Feb 2022 23:35:44 +0100 Subject: [PATCH] #11 Hide news carousel if there are none --- src/news/container/News.tsx | 6 +++--- src/news/store/types.ts | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/news/container/News.tsx b/src/news/container/News.tsx index 144d2e3b..e831ed14 100644 --- a/src/news/container/News.tsx +++ b/src/news/container/News.tsx @@ -45,7 +45,7 @@ const News: React.FC = () => { dispatch(NewsActions.load()); }, [newsList]); - const carouselItems = newsList?.map(entry => ( + const carouselItems = newsList?.filter(entry => entry.frontpage).map(entry => ( {entry.image && {entry.title}} @@ -53,14 +53,14 @@ const News: React.FC = () => {

{entry.content}

- )); + )) ?? []; return ( {news.pending === PendingState.LOADING && ( )} - {carouselItems != null && ( + {carouselItems.length > 0 && ( 1} indicators={carouselItems.length > 1}> {carouselItems} diff --git a/src/news/store/types.ts b/src/news/store/types.ts index f96d39a3..04316541 100644 --- a/src/news/store/types.ts +++ b/src/news/store/types.ts @@ -3,24 +3,27 @@ import ArrayReducerType from '../../common/store/ArrayReducerType'; import { ACTION, GenericArrayReducerAction } from '../../common/store/ReduxHelper'; export type NewsItemDto = { - id: number; - image: string; - title: string; - content: string; + id: number; + image: string; + title: string; + content: string; + frontpage: boolean; } export type NewsItem = { - id: number; - image: string; - title: string; - content: string; + id: number; + image: string; + title: string; + content: string; + frontpage: boolean; } export const toNewsItem = (dto: NewsItemDto): NewsItem => ({ - id: dto.id, - image: dto.image, - title: dto.title, - content: dto.content, + id: dto.id, + image: dto.image, + title: dto.title, + content: dto.content, + frontpage: dto.frontpage, }); export const NEWS_STORE = '@@news';