Simplifies all-day event row calculation
Replaces date expansion logic with direct inspection of CSS grid row styles. This improves accuracy and performance by reflecting the actual rendered layout for determining `maxRows`.
This commit is contained in:
parent
c682c30e23
commit
c9b9ac4cae
1 changed files with 14 additions and 33 deletions
|
|
@ -183,45 +183,26 @@ export class AllDayManager {
|
|||
|
||||
const allDayEvents = container.querySelectorAll('swp-event');
|
||||
|
||||
|
||||
// Calculate required rows - 0 if no events (will collapse)
|
||||
let maxRows = 0;
|
||||
|
||||
if (allDayEvents.length > 0) {
|
||||
// Expand events to all dates they span and group by date
|
||||
const expandedEventsByDate: Record<string, string[]> = {};
|
||||
// Track which rows are actually used by checking grid positions
|
||||
const usedRows = new Set<number>();
|
||||
|
||||
(Array.from(allDayEvents) as HTMLElement[]).forEach((event: HTMLElement) => {
|
||||
const startISO = event.dataset.start || '';
|
||||
const endISO = event.dataset.end || startISO;
|
||||
const eventId = event.dataset.eventId || '';
|
||||
|
||||
// Extract dates from ISO strings
|
||||
const startDate = startISO.split('T')[0]; // YYYY-MM-DD
|
||||
const endDate = endISO.split('T')[0]; // YYYY-MM-DD
|
||||
|
||||
// Loop through all dates from start to end
|
||||
let current = new Date(startDate);
|
||||
const end = new Date(endDate);
|
||||
|
||||
while (current <= end) {
|
||||
const dateStr = current.toISOString().split('T')[0]; // YYYY-MM-DD format
|
||||
|
||||
if (!expandedEventsByDate[dateStr]) {
|
||||
expandedEventsByDate[dateStr] = [];
|
||||
}
|
||||
expandedEventsByDate[dateStr].push(eventId);
|
||||
|
||||
// Move to next day
|
||||
current.setDate(current.getDate() + 1);
|
||||
}
|
||||
const gridRow = parseInt(getComputedStyle(event).gridRowStart) || 1;
|
||||
usedRows.add(gridRow);
|
||||
});
|
||||
|
||||
// Find max rows needed
|
||||
maxRows = Math.max(
|
||||
...Object.values(expandedEventsByDate).map(ids => ids?.length || 0),
|
||||
0
|
||||
);
|
||||
// Max rows = highest row number in use
|
||||
maxRows = usedRows.size > 0 ? Math.max(...usedRows) : 0;
|
||||
|
||||
console.log('🔍 AllDayManager: Height calculation', {
|
||||
totalEvents: allDayEvents.length,
|
||||
usedRows: Array.from(usedRows).sort(),
|
||||
maxRows
|
||||
});
|
||||
}
|
||||
|
||||
// Animate to required rows (0 = collapse, >0 = expand)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue