Skip to content

Commit

Permalink
fix: add workaround to hide duplicate occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
GamerBene19 committed Oct 16, 2022
1 parent 3cec010 commit d38bcaf
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/components/today-overview/TodayOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'next-i18next';
import React from 'react';
import React, { useMemo } from 'react';
import {
GetOccurrencesByDateQuery,
GetOccurrencesByDateQueryVariables,
Expand Down Expand Up @@ -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) => (
<Occurrence occurrence={occurrence} key={occurrence.id} />
));

Expand Down

0 comments on commit d38bcaf

Please sign in to comment.