Skip to content

Commit d4f14bd

Browse files
Merge pull request #87 from linked-planet/dev
timetable - small stabilization (WIP)
2 parents 8530b20 + 1024f00 commit d4f14bd

File tree

1 file changed

+58
-43
lines changed

1 file changed

+58
-43
lines changed

library/src/components/timetable/TimeTableRows.tsx

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const rowsMargin = 1
7272

7373
function renderGroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>(
7474
renderCells: [number, number],
75-
//entries: TimeTableEntry<G, I>[],
7675
groupRows: Map<G, ItemRowEntry<I>[][] | null>,
7776
g: number,
7877
refCollection: React.MutableRefObject<HTMLElement>[],
@@ -106,6 +105,8 @@ function renderGroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>(
106105
g,
107106
groupEntriesArray,
108107
groupEntry,
108+
groupRows,
109+
groupEntriesArray,
109110
)
110111
throw new Error("TimeTable - group entry not found")
111112
}
@@ -134,8 +135,6 @@ function renderGroupRows<G extends TimeTableGroup, I extends TimeSlotBooking>(
134135
}
135136
changedGroupRows.delete(g)
136137

137-
console.log("RENDERING", g, groupEntry.title, rendering)
138-
139138
groupRowsRendered[g] = (
140139
<GroupRows<G, I>
141140
key={`${groupEntry.title}${g}-${rendering}`}
@@ -235,12 +234,10 @@ export default function TimeTableRows<
235234
// those are rendered, others are only rendered as placeholder (1 div per group, instead of multiple rows and cells)
236235
const handleIntersections = useCallback(() => {
237236
if (!refCollection.current.length) {
238-
console.log("WARG")
239237
return
240238
}
241239
if (!refCollection.current[0] || !refCollection.current[0].current) {
242240
// placeholders not yet rendered
243-
console.log("WARG2", refCollection.current)
244241
return
245242
}
246243
if (!intersectionContainerRef.current || !headerRef.current) {
@@ -315,15 +312,21 @@ export default function TimeTableRows<
315312
}
316313
}
317314
// detect to render
318-
for (let i = newRenderCells[0]; i <= newRenderCells[1]; i++) {
319-
if (!renderedGroups.current.has(i)) {
320-
changedGroupRows.current.add(i)
315+
if (newRenderCells[0] > -1) {
316+
for (
317+
let i = newRenderCells[0];
318+
i <= newRenderCells[1];
319+
i++
320+
) {
321+
if (!renderedGroups.current.has(i)) {
322+
changedGroupRows.current.add(i)
323+
}
321324
}
322325
}
323-
console.log(
326+
/*console.log(
324327
"TimeTable - intersection group rows changed",
325328
newRenderCells,
326-
)
329+
)*/
327330
renderGroupRangeRef.current = newRenderCells
328331
return newRenderCells
329332
}
@@ -353,9 +356,19 @@ export default function TimeTableRows<
353356
}
354357
}
355358
setCurrentGroupRows((currentGroupRows) => {
359+
changedGroupRows.current.clear()
360+
if (groupRows.size < currentGroupRows.size) {
361+
refCollection.current.length = groupRows.size
362+
groupRowsRendered.current.length = groupRows.size
363+
}
364+
356365
if (!groupRows) {
357366
setGroupRowsRenderedIdx(-1)
358367
groupRowsRenderedIdxRef.current = 0
368+
groupRowsRendered.current = []
369+
renderedGroups.current.clear()
370+
refCollection.current = []
371+
console.log("TimeTable - group rows are null")
359372
return groupRows
360373
}
361374

@@ -370,6 +383,7 @@ export default function TimeTableRows<
370383
const currentRows = currentGroupRows.get(group)
371384
if (
372385
(rows !== currentRows &&
386+
renderGroupRangeRef.current[0] > -1 &&
373387
i >= renderGroupRangeRef.current[0] &&
374388
i <= renderGroupRangeRef.current[1]) ||
375389
rows?.length !== currentRows?.length
@@ -381,15 +395,15 @@ export default function TimeTableRows<
381395
changedGroupRows.current.add(i)
382396
}
383397
}
384-
for (const chrangeG of changedGroupRows.current) {
385-
if (chrangeG > keys.length - 1) {
398+
for (const changedG of changedGroupRows.current) {
399+
if (changedG > keys.length - 1) {
386400
// delete obsolete change
387-
changedGroupRows.current.delete(chrangeG)
401+
changedGroupRows.current.delete(changedG)
388402
}
389403
}
390404

391405
console.log(
392-
"PERF UPDATE GROUP ROWS",
406+
"PERF UPDATE GROUP ROWS ENTRIES",
393407
performance.now() - perf_Start,
394408
changedGroupRows.current,
395409
keys.length,
@@ -441,34 +455,36 @@ export default function TimeTableRows<
441455
setGroupRowsRenderedIdx((groupRowsRenderedIdx) => {
442456
if (changedGroupRows.current.size) {
443457
let counter = 0
444-
for (
445-
let i = renderGroupRangeRef.current[0];
446-
i <= renderGroupRangeRef.current[1];
447-
i++
448-
) {
449-
// make sure visible rows are rendered
450-
if (changedGroupRows.current.has(i)) {
451-
renderGroupRows(
452-
renderGroupRangeRef.current,
453-
currentGroupRows,
454-
i,
455-
refCollection.current,
456-
groupRowsRendered.current,
457-
renderedGroups.current,
458-
changedGroupRows.current,
459-
onGroupClick,
460-
placeHolderHeight,
461-
columnWidth,
462-
rowHeight,
463-
selectedTimeSlotItem,
464-
onTimeSlotItemClick,
465-
slotsArray,
466-
timeFrameDay,
467-
viewType,
468-
)
469-
counter++
470-
if (counter > timeTableGroupRenderBatchSize) {
471-
return groupRowsRenderedIdx - 1
458+
if (renderGroupRangeRef.current[0] > -1) {
459+
for (
460+
let i = renderGroupRangeRef.current[0];
461+
i <= renderGroupRangeRef.current[1];
462+
i++
463+
) {
464+
// make sure visible rows are rendered
465+
if (changedGroupRows.current.has(i)) {
466+
renderGroupRows(
467+
renderGroupRangeRef.current,
468+
currentGroupRows,
469+
i,
470+
refCollection.current,
471+
groupRowsRendered.current,
472+
renderedGroups.current,
473+
changedGroupRows.current,
474+
onGroupClick,
475+
placeHolderHeight,
476+
columnWidth,
477+
rowHeight,
478+
selectedTimeSlotItem,
479+
onTimeSlotItemClick,
480+
slotsArray,
481+
timeFrameDay,
482+
viewType,
483+
)
484+
counter++
485+
if (counter > timeTableGroupRenderBatchSize) {
486+
return groupRowsRenderedIdx - 1
487+
}
472488
}
473489
}
474490
}
@@ -503,7 +519,6 @@ export default function TimeTableRows<
503519

504520
//normal placeholder rendering
505521
let ret = groupRowsRendered.current.length
506-
console.log("RET START", ret, groupRowsRenderedIdx)
507522
let counter = 0
508523
while (
509524
ret < currentGroupRows.size &&

0 commit comments

Comments
 (0)