Skip to content

Commit

Permalink
Merge events by columns
Browse files Browse the repository at this point in the history
  • Loading branch information
user890104 committed Sep 30, 2024
1 parent f99cd4b commit d48b5d0
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions src/hooks/useScheduleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,60 @@ export default function useScheduleTable({
...filteredHalls,
];

const rows = microslots.flatMap((date, index, array) => {
const isFirst = index === 0;
const isLast = index === array.length - 1;
const nextDate = !isLast ? array[index + 1] : null;
const isFirstForTheDay = index > 0 && !isSameDay(date, array[index - 1]);
const isLastForTheDay = array?.[index + 1] && !isSameDay(date, array[index + 1]);

const eventCells = filteredHalls.map(hall => {
const slot = filteredSlots.find(slot =>
slot.hall_id === hall.id &&
compareAsc(slot.starts_at, date) === 0
);

if (!slot) {
return {
const rows = microslots.flatMap((date, slotsIndex, slotsArray) => {
const isFirst = slotsIndex === 0;
const isLast = slotsIndex === slotsArray.length - 1;
const nextDate = !isLast ? slotsArray[slotsIndex + 1] : null;
const isFirstForTheDay = slotsIndex > 0 && !isSameDay(date, slotsArray[slotsIndex - 1]);
const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]);
const processedEvents = new Set();

const eventCells = filteredHalls.flatMap((hall, hallIndex, hallsArray) => {
const currentTimeSlots = filteredSlots.filter(slot => compareAsc(slot.starts_at, date) === 0);
const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id);

if (!currentHallSlot) {
return [{
id: 'blank-'.concat(hall.id),
};
}];
}

if (processedEvents.has(currentHallSlot.event_id)) {
return [];
}

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(slot.id),
return [{
id: 'slot-'.concat(currentHallSlot.id),
attributes: {
className: 'schedule-'.concat(slot.event.language).concat(' ').concat(slot.event.track?.css_class),
className: 'schedule-'.concat(currentHallSlot.event.language).concat(' ').concat(currentHallSlot.event.track?.css_class),
colSpan,
},
event: slot.event,
};
event: currentHallSlot.event,
}];
});
const isEmptyRow = !eventCells.find(slot => !!slot.event);

const isEmptyRow = !eventCells.find(slot => !!slot?.event);
const showHeader = isFirst || isFirstForTheDay;
const showSlot = !isLast && !isLastForTheDay && !isEmptyRow;

Expand Down

0 comments on commit d48b5d0

Please sign in to comment.