Optimize schedule table rendering

This commit is contained in:
Vencislav Atanasov 2024-09-23 18:48:43 +03:00
parent 70b1b36852
commit 4128e0e68a
1 changed files with 22 additions and 19 deletions

View File

@ -6,10 +6,12 @@ export default function useScheduleTable({
events = {}, events = {},
slots = {}, slots = {},
}) { }) {
const filteredEvents = useMemo(() => events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true), [eventTypeId, events]); return useMemo(() => {
const filteredEventIds = useMemo(() => filteredEvents.map(event => event.id), [filteredEvents]); const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true);
const filteredHallIds = useMemo(() => new Set(slots.filter(slot => filteredEventIds.includes(slot.event_id)).map(slot => slot.hall_id)), [filteredEventIds, slots]); const filteredEventIds = filteredEvents.map(event => event.id);
const header = useMemo(() => halls.filter(hall => filteredHallIds.has(hall.id)), [filteredHallIds, halls]); 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 => ({ const rows = filteredEvents.map(event => ({
id: event.id, id: event.id,
@ -27,4 +29,5 @@ export default function useScheduleTable({
header, header,
rows, rows,
}; };
}, [eventTypeId, events, halls, slots]);
} }