From 49925f129943b975563a8111522b579245cb5c3a Mon Sep 17 00:00:00 2001 From: Anemaygi Date: Fri, 15 Nov 2024 12:37:32 -0300 Subject: [PATCH] Arrumar reduce do filtro --- .../src/components/Blocks/Calendario/View.jsx | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/frontend/packages/portalbrasil-intranet/src/components/Blocks/Calendario/View.jsx b/frontend/packages/portalbrasil-intranet/src/components/Blocks/Calendario/View.jsx index 3022e17..ef3ebb1 100644 --- a/frontend/packages/portalbrasil-intranet/src/components/Blocks/Calendario/View.jsx +++ b/frontend/packages/portalbrasil-intranet/src/components/Blocks/Calendario/View.jsx @@ -5,34 +5,32 @@ import { parseDate } from '@internationalized/date'; import withQuerystringResults from './withQuerystringResults'; const groupByDate = (items) => { - return Object.values( - items - .reduce((map, obj) => { - if (!obj.start) { - return null; - } - - let start = obj.start ? parseDate(obj.start.slice(0, 10)) : null; - const end = obj.end ? parseDate(obj.end.slice(0, 10)) : start; + return items.reduce((map, obj) => { + if (!obj.start) { + return map; + } - while (start < end) { - const key = start.toString(); + let start = obj.start ? parseDate(obj.start.slice(0, 10)) : null; + const end = obj.end ? parseDate(obj.end.slice(0, 10)) : start; - if (key) { - if (map[key] === undefined) { - map[key] = []; - } - map[key].push(obj); - } + while (start < end) { + const key = start.toString(); - start = start.add({ days: 1 }); + if (key) { + if (map[key] === undefined) { + map[key] = []; } - return map; - }, {}) - ).filter((item) => item !== null); + map[key].push(obj); + } + + start = start.add({ days: 1 }); + } + return map; + }, {}); }; + const CalendarioBlockView = withQuerystringResults((props) => { const { data, isEditMode, path, pathname, className, listingItems } = props; const items = listingItems ? groupByDate(listingItems) : {};