From 4128e0e68aa28edb1c37aaf16adf321a9f45ebf0 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 23 Sep 2024 18:48:43 +0300 Subject: [PATCH] Optimize schedule table rendering --- src/hooks/useScheduleTable.js | 41 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/hooks/useScheduleTable.js b/src/hooks/useScheduleTable.js index f5ecd0f..3baf81b 100644 --- a/src/hooks/useScheduleTable.js +++ b/src/hooks/useScheduleTable.js @@ -6,25 +6,28 @@ export default function useScheduleTable({ events = {}, slots = {}, }) { - const filteredEvents = useMemo(() => events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true), [eventTypeId, events]); - const filteredEventIds = useMemo(() => filteredEvents.map(event => event.id), [filteredEvents]); - const filteredHallIds = useMemo(() => new Set(slots.filter(slot => filteredEventIds.includes(slot.event_id)).map(slot => slot.hall_id)), [filteredEventIds, slots]); - const header = useMemo(() => halls.filter(hall => filteredHallIds.has(hall.id)), [filteredHallIds, halls]); + return useMemo(() => { + const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true); + const filteredEventIds = filteredEvents.map(event => event.id); + const filteredSlots = slots.filter(slot => filteredEventIds.includes(slot.event_id)); + const filteredHallIds = new Set(filteredSlots.map(slot => slot.hall_id)); + const header = halls.filter(hall => filteredHallIds.has(hall.id)); - const rows = filteredEvents.map(event => ({ - id: event.id, - cells: [{ - id: 1, - attributes: { - className: 'schedule-'.concat(event.language).concat(' ').concat(event.track?.css_class), - colSpan: 2, - }, - event, - }], - })); + const rows = filteredEvents.map(event => ({ + id: event.id, + cells: [{ + id: 1, + attributes: { + className: 'schedule-'.concat(event.language).concat(' ').concat(event.track?.css_class), + colSpan: 2, + }, + event, + }], + })); - return { - header, - rows, - }; + return { + header, + rows, + }; + }, [eventTypeId, events, halls, slots]); }