Skip to content

Commit

Permalink
time table - refactored update of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-wishes committed Nov 26, 2024
1 parent 0c855c8 commit ca28322
Showing 1 changed file with 44 additions and 46 deletions.
90 changes: 44 additions & 46 deletions library/src/components/timetable/TimeTableRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,59 +225,57 @@ export default function TimeTableRows<
entries.length,
])

//const currentGroupRows = useRef(groupRows)
const [currentGroupRows, setCurrentGroupRows] = useState(groupRows)
const currentGroupRows = useRef(groupRows)
//const [currentGroupRows, setCurrentGroupRows] = useState(groupRows)

// initial run
useEffect(() => {
setCurrentGroupRows((currentGroupRows) => {
if (!currentGroupRows) {
setCurrentGroupRows(groupRows)
setGroupRowsRenderedIdx(0)
groupRowsRenderedIdxRef.current = 0
console.info("TimeTable - all group rows updated")
return currentGroupRows
if (!currentGroupRows.current) {
currentGroupRows.current = groupRows
setGroupRowsRenderedIdx(0)
groupRowsRenderedIdxRef.current = 0
console.info("TimeTable - all group rows updated")
return
}
// determine when new ones start
let newOne = -1
const keys = Object.keys(currentGroupRows)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (!groupRows[key]) {
newOne = i
break
}
// determine when new ones start
let newOne = -1
const keys = Object.keys(currentGroupRows)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (!groupRows[key]) {
newOne = i
break
}
if (
(groupRows[key] !== currentGroupRows[key] &&
i >= renderCells.current[0] &&
i <= renderCells.current[1]) ||
groupRows[key]?.length !== currentGroupRows[key]?.length
) {
newOne = i
break
}
if (
(groupRows[key] !== currentGroupRows.current[key] &&
i >= renderCells.current[0] &&
i <= renderCells.current[1]) ||
groupRows[key]?.length !== currentGroupRows.current[key]?.length
) {
newOne = i
break
}
if (newOne === -1) {
if (keys.length === Object.keys(groupRows).length) {
console.info(
"TimeTable - group rows have no changes",
keys.length,
)
return currentGroupRows
}
newOne = keys.length
}
if (newOne === -1) {
if (keys.length === Object.keys(groupRows).length) {
console.info(
"TimeTable - group rows have no changes",
keys.length,
)
currentGroupRows.current = groupRows
return
}
// we need to render the new ones
setGroupRowsRenderedIdx((prev) => {
const ret = prev >= newOne ? newOne : prev
if (ret === newOne) {
allPlaceholderRendered.current = false
}
return ret
})
return groupRows
newOne = keys.length
}
// we need to render the new ones
setGroupRowsRenderedIdx((prev) => {
const ret = prev >= newOne ? newOne : prev
if (ret === newOne) {
allPlaceholderRendered.current = false
}
return ret
})

currentGroupRows.current = groupRows
//rateLimiterRendering(() => window.setTimeout(renderBatch, 0))
}, [groupRows])
//useEffect(handleIntersections, [])
Expand Down

0 comments on commit ca28322

Please sign in to comment.