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');
|
const allDayEvents = container.querySelectorAll('swp-event');
|
||||||
|
|
||||||
|
|
||||||
// Calculate required rows - 0 if no events (will collapse)
|
// Calculate required rows - 0 if no events (will collapse)
|
||||||
let maxRows = 0;
|
let maxRows = 0;
|
||||||
|
|
||||||
if (allDayEvents.length > 0) {
|
if (allDayEvents.length > 0) {
|
||||||
// Expand events to all dates they span and group by date
|
// Track which rows are actually used by checking grid positions
|
||||||
const expandedEventsByDate: Record<string, string[]> = {};
|
const usedRows = new Set<number>();
|
||||||
|
|
||||||
(Array.from(allDayEvents) as HTMLElement[]).forEach((event: HTMLElement) => {
|
(Array.from(allDayEvents) as HTMLElement[]).forEach((event: HTMLElement) => {
|
||||||
const startISO = event.dataset.start || '';
|
const gridRow = parseInt(getComputedStyle(event).gridRowStart) || 1;
|
||||||
const endISO = event.dataset.end || startISO;
|
usedRows.add(gridRow);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Find max rows needed
|
// Max rows = highest row number in use
|
||||||
maxRows = Math.max(
|
maxRows = usedRows.size > 0 ? Math.max(...usedRows) : 0;
|
||||||
...Object.values(expandedEventsByDate).map(ids => ids?.length || 0),
|
|
||||||
0
|
console.log('🔍 AllDayManager: Height calculation', {
|
||||||
);
|
totalEvents: allDayEvents.length,
|
||||||
|
usedRows: Array.from(usedRows).sort(),
|
||||||
|
maxRows
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animate to required rows (0 = collapse, >0 = expand)
|
// Animate to required rows (0 = collapse, >0 = expand)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue