Compare commits
No commits in common. "b3585ee1cefd412f784389dc21de6b9adc70eedd" and "87783809f88acf9743276f2d8b1db3b3feeaf222" have entirely different histories.
b3585ee1ce
...
87783809f8
|
@ -1,5 +1,5 @@
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { sorter } from '../utils.js';
|
import { sorter, toMidnight } from '../utils.js';
|
||||||
import { langs } from '../Schedule/constants.js';
|
import { langs } from '../Schedule/constants.js';
|
||||||
import { compareAsc, getTime, isSameDay, toDate } from 'date-fns';
|
import { compareAsc, getTime, isSameDay, toDate } from 'date-fns';
|
||||||
|
|
||||||
|
@ -13,13 +13,20 @@ export default function useScheduleTable({
|
||||||
const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true);
|
const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true);
|
||||||
const filteredEventIds = filteredEvents.map(event => event.id);
|
const filteredEventIds = filteredEvents.map(event => event.id);
|
||||||
const filteredSlots = slots.sort(sorter('starts_at')).filter(slot => filteredEventIds.includes(slot.event_id));
|
const filteredSlots = slots.sort(sorter('starts_at')).filter(slot => filteredEventIds.includes(slot.event_id));
|
||||||
|
const days = Array.from(new Set(filteredSlots.map(slot => getTime(toMidnight(slot))))).map(ts => toDate(ts));
|
||||||
const microslots = Array.from(new Set(filteredSlots.flatMap(slot => [
|
const microslots = Array.from(new Set(filteredSlots.flatMap(slot => [
|
||||||
getTime(slot.starts_at),
|
getTime(slot.starts_at),
|
||||||
getTime(slot.ends_at),
|
getTime(slot.ends_at),
|
||||||
]))).sort().map(ts => toDate(ts));
|
]))).sort().map(ts => toDate(ts));
|
||||||
const filteredHallIds = new Set(filteredSlots.map(slot => slot.hall_id));
|
const filteredHallIds = new Set(filteredSlots.map(slot => slot.hall_id));
|
||||||
const filteredHalls = halls.filter(hall => filteredHallIds.has(hall.id));
|
const filteredHalls = halls.filter(hall => filteredHallIds.has(hall.id));
|
||||||
const skipHallSlots = new Map();
|
const hallSlots = Object.fromEntries(filteredHalls.map(hall => [
|
||||||
|
hall.id,
|
||||||
|
filteredSlots.filter(slot => slot.hall_id === hall.id),
|
||||||
|
]));
|
||||||
|
|
||||||
|
void(days);
|
||||||
|
void(hallSlots);
|
||||||
|
|
||||||
const header = [{
|
const header = [{
|
||||||
id: 0,
|
id: 0,
|
||||||
|
@ -34,22 +41,9 @@ export default function useScheduleTable({
|
||||||
const nextDate = !isLast ? slotsArray[slotsIndex + 1] : null;
|
const nextDate = !isLast ? slotsArray[slotsIndex + 1] : null;
|
||||||
const isFirstForTheDay = slotsIndex > 0 && !isSameDay(date, slotsArray[slotsIndex - 1]);
|
const isFirstForTheDay = slotsIndex > 0 && !isSameDay(date, slotsArray[slotsIndex - 1]);
|
||||||
const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]);
|
const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]);
|
||||||
const rowEvents = new Set();
|
const processedEvents = new Set();
|
||||||
|
|
||||||
const eventCells = filteredHalls.flatMap((hall, hallIndex, hallsArray) => {
|
const eventCells = filteredHalls.flatMap((hall, hallIndex, hallsArray) => {
|
||||||
if (skipHallSlots.has(hall.id)) {
|
|
||||||
const leftToSkip = skipHallSlots.get(hall.id);
|
|
||||||
|
|
||||||
if (leftToSkip <= 1) {
|
|
||||||
skipHallSlots.delete(hall.id);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipHallSlots.set(hall.id, leftToSkip - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentTimeSlots = filteredSlots.filter(slot => compareAsc(slot.starts_at, date) === 0);
|
const currentTimeSlots = filteredSlots.filter(slot => compareAsc(slot.starts_at, date) === 0);
|
||||||
const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id);
|
const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id);
|
||||||
|
|
||||||
|
@ -59,25 +53,10 @@ export default function useScheduleTable({
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowEvents.has(currentHallSlot.event_id)) {
|
if (processedEvents.has(currentHallSlot.event_id)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let rowSpan = 1;
|
|
||||||
|
|
||||||
const spanningMicroslots = microslots.filter(slotDate =>
|
|
||||||
currentHallSlot.starts_at <= slotDate &&
|
|
||||||
currentHallSlot.ends_at >= slotDate
|
|
||||||
);
|
|
||||||
|
|
||||||
if (spanningMicroslots.length > 1) {
|
|
||||||
rowSpan = spanningMicroslots.length - 1;
|
|
||||||
|
|
||||||
if (rowSpan > 1) {
|
|
||||||
skipHallSlots.set(hall.id, rowSpan - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let colSpan = 1;
|
let colSpan = 1;
|
||||||
|
|
||||||
for (const index of hallsArray.keys()) {
|
for (const index of hallsArray.keys()) {
|
||||||
|
@ -95,7 +74,7 @@ export default function useScheduleTable({
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rowEvents.add(currentHallSlot.event_id);
|
processedEvents.add(currentHallSlot.event_id);
|
||||||
colSpan++;
|
colSpan++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +83,12 @@ export default function useScheduleTable({
|
||||||
attributes: {
|
attributes: {
|
||||||
className: 'schedule-'.concat(currentHallSlot.event.language).concat(' ').concat(currentHallSlot.event.track?.css_class),
|
className: 'schedule-'.concat(currentHallSlot.event.language).concat(' ').concat(currentHallSlot.event.track?.css_class),
|
||||||
colSpan,
|
colSpan,
|
||||||
rowSpan,
|
|
||||||
},
|
},
|
||||||
event: currentHallSlot.event,
|
event: currentHallSlot.event,
|
||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
|
|
||||||
const isEmptyRow = false; // TODO !eventCells.find(slot => !!slot?.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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue