Merge events by columns

This commit is contained in:
Vencislav Atanasov 2024-09-30 19:41:06 +03:00
parent f99cd4bdaa
commit d48b5d05d4
1 changed files with 48 additions and 23 deletions

View File

@ -35,35 +35,60 @@ export default function useScheduleTable({
...filteredHalls, ...filteredHalls,
]; ];
const rows = microslots.flatMap((date, index, array) => { const rows = microslots.flatMap((date, slotsIndex, slotsArray) => {
const isFirst = index === 0; const isFirst = slotsIndex === 0;
const isLast = index === array.length - 1; const isLast = slotsIndex === slotsArray.length - 1;
const nextDate = !isLast ? array[index + 1] : null; const nextDate = !isLast ? slotsArray[slotsIndex + 1] : null;
const isFirstForTheDay = index > 0 && !isSameDay(date, array[index - 1]); const isFirstForTheDay = slotsIndex > 0 && !isSameDay(date, slotsArray[slotsIndex - 1]);
const isLastForTheDay = array?.[index + 1] && !isSameDay(date, array[index + 1]); const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]);
const processedEvents = new Set();
const eventCells = filteredHalls.map(hall => { const eventCells = filteredHalls.flatMap((hall, hallIndex, hallsArray) => {
const slot = filteredSlots.find(slot => const currentTimeSlots = filteredSlots.filter(slot => compareAsc(slot.starts_at, date) === 0);
slot.hall_id === hall.id && const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id);
compareAsc(slot.starts_at, date) === 0
);
if (!slot) { if (!currentHallSlot) {
return { return [{
id: 'blank-'.concat(hall.id), id: 'blank-'.concat(hall.id),
}; }];
} }
return { if (processedEvents.has(currentHallSlot.event_id)) {
id: 'slot-'.concat(slot.id), return [];
attributes: { }
className: 'schedule-'.concat(slot.event.language).concat(' ').concat(slot.event.track?.css_class),
},
event: slot.event,
};
});
const isEmptyRow = !eventCells.find(slot => !!slot.event);
let colSpan = 1;
for (const index of hallsArray.keys()) {
if (index <= hallIndex) {
continue;
}
const currentHall = hallsArray[index];
const currentSlot = currentTimeSlots.find(slot =>
slot.hall_id === currentHall.id &&
slot.event_id === currentHallSlot.event_id
);
if (!currentSlot) {
break;
}
processedEvents.add(currentHallSlot.event_id);
colSpan++;
}
return [{
id: 'slot-'.concat(currentHallSlot.id),
attributes: {
className: 'schedule-'.concat(currentHallSlot.event.language).concat(' ').concat(currentHallSlot.event.track?.css_class),
colSpan,
},
event: currentHallSlot.event,
}];
});
const isEmptyRow = !eventCells.find(slot => !!slot?.event);
const showHeader = isFirst || isFirstForTheDay; const showHeader = isFirst || isFirstForTheDay;
const showSlot = !isLast && !isLastForTheDay && !isEmptyRow; const showSlot = !isLast && !isLastForTheDay && !isEmptyRow;