From d38bcaf9c6a09bded0e455f24c76aaf7cc7fdfe3 Mon Sep 17 00:00:00 2001 From: Benedikt Nerb Date: Sun, 16 Oct 2022 23:50:07 +0200 Subject: [PATCH] fix: add workaround to hide duplicate occurrences --- .../today-overview/TodayOverview.tsx | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/today-overview/TodayOverview.tsx b/src/components/today-overview/TodayOverview.tsx index 41c2281..1d3247e 100644 --- a/src/components/today-overview/TodayOverview.tsx +++ b/src/components/today-overview/TodayOverview.tsx @@ -1,5 +1,5 @@ import { useTranslation } from 'next-i18next'; -import React from 'react'; +import React, { useMemo } from 'react'; import { GetOccurrencesByDateQuery, GetOccurrencesByDateQueryVariables, @@ -33,9 +33,30 @@ const TodayOverview = () => { skip: !navData || navData.selectedDate.length < DATE_FORMAT.length, }); + // Remove duplicate occurrences. This hack is needed because there were + // bugs in the backend that caused duplicate occurrences + // TODO: Remove once those duplicated entries are deleted + const uniqueOccurrences = useMemo(() => { + const uniqueDishIds = data?.occurrences + .map((occ) => occ.dish.id) + // Only pick the first occurrence of each id + .filter((val, idx, arr) => arr.indexOf(val) === idx); + + return ( + data?.occurrences && + uniqueDishIds?.map( + (id) => + // Find (first) occurrence with that id or just use the first one + // Note: The latter should not occur and is a quick workaround to achieve proper typing + data.occurrences.find((occ) => occ.dish.id == id) || + data.occurrences[0], + ) + ); + }, [data?.occurrences]); + const content = - data && - data.occurrences.map((occurrence) => ( + uniqueOccurrences && + uniqueOccurrences.map((occurrence) => ( ));