Skip to content

Commit 5a3b474

Browse files
Merge pull request #100 from linked-planet/dev
Dev
2 parents e444020 + dd21031 commit 5a3b474

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

library/src/components/inputs/datetimepicker/TimePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function useOptions({
108108
.map((it) => Number.parseInt(it) ?? 0)
109109
let end = dayjs().hour(endHourMin[0]).minute(endHourMin[1])
110110
let curr = dayjs().hour(startHourMin[0]).minute(startHourMin[1])
111-
if (end.isSame(curr)) {
111+
if (end.isSame(curr) || end.isBefore(curr)) {
112112
end = end.add(1, "day")
113113
}
114114

library/src/components/timetable/TimeTableRows.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,24 @@ export default function TimeTableRows<
367367
`Timetable - shorten rendered elements array from ${groupRowsRendered.length} to ${groupRows.size}`,
368368
)
369369
setGroupRowsRendered(groupRowsRendered.slice(0, groupRows.size))
370+
for (const changedG of changedGroupRows.current) {
371+
if (changedG > groupRows.size - 1) {
372+
changedGroupRows.current.delete(changedG)
373+
}
374+
}
375+
for (const renderedG of renderedGroups.current) {
376+
if (renderedG > groupRows.size - 1) {
377+
renderedGroups.current.delete(renderedG)
378+
}
379+
}
370380
refCollection.current.length = groupRows.size
381+
if (renderGroupRangeRef.current[0] > groupRows.size - 1) {
382+
renderGroupRangeRef.current = [0, groupRows.size - 1]
383+
setRenderGroupRange([0, groupRows.size - 1])
384+
}
385+
if (refCollection.current.length < groupRows.size) {
386+
refCollection.current.length = groupRows.size
387+
}
371388
}
372389

373390
// determine when new ones start
@@ -398,18 +415,11 @@ export default function TimeTableRows<
398415
changedGroupRows.current.delete(changedG)
399416
}
400417
}
401-
for (const renderedG of renderedGroups.current) {
402-
if (renderedG > keys.length - 1) {
403-
// delete obsolete change
404-
renderedGroups.current.delete(renderedG)
405-
}
406-
}
407418

408419
if (updateCounter) {
409420
console.log(
410421
`TimeTable - group rows require updated rendering ${updateCounter}, with first ${changedFound}`,
411422
renderGroupRangeRef.current,
412-
currentGroupRowsRef.current.size,
413423
groupRows.size,
414424
)
415425
} else {
@@ -557,6 +567,9 @@ export default function TimeTableRows<
557567
)
558568
++counter
559569
}
570+
if (groupRowsRendered.length > currentGroupRowsRef.current.size) {
571+
groupRowsRendered.length = currentGroupRowsRef.current.size
572+
}
560573
rateLimiterIntersection(handleIntersections)
561574
return groupRowsRendered
562575
})

library/src/components/timetable/timeTableUtils.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,19 @@ export function getLeftAndWidth(
432432
}
433433

434434
const slotStart = slotsArray[startSlot]
435+
const ddaysDiff = itemModStart.diff(slotStart, "day")
436+
const startDiffDays = ddaysDiff * timeFrameDay.oneDayMinutes
437+
438+
const dayStartDiff =
439+
viewType === "hours"
440+
? 0
441+
: timeFrameDay.startHour * 60 + timeFrameDay.startMinute
442+
const startSum = startDiffDays + dayStartDiff
443+
444+
const slotStartDiff = itemModStart.diff(slotStart, "minute")
445+
446+
const left = (slotStartDiff - startSum) / timeSlotMinutes
435447

436-
const dstartMin = itemModStart.diff(slotStart, "minute")
437-
let left = dstartMin / timeSlotMinutes
438448
if (left < 0) {
439449
console.error(
440450
"LPTimeTable - item with negative left found:",
@@ -445,35 +455,15 @@ export function getLeftAndWidth(
445455
slotsArray,
446456
timeSlotMinutes,
447457
)
448-
// if the start is before the time slot, we need to set the left to 0
449-
left = 0
450458
}
451459

452460
const timeSpanMin = itemModEnd.diff(itemModStart, "minute")
453461
const width = timeSpanMin / timeSlotMinutes
454462

455-
/*let dmin = itemModEnd.diff(slotsArray[endSlot], "minute")
456-
// because of the time frame of the day, i need to remove the amount if minutes missing to the days end * the amount of days of the time slot to get the correct end
457-
if (viewType !== "hours") {
458-
const daysCount = Math.floor(dmin / (26 * 60))
459-
if (daysCount > 0) {
460-
const diffToDayEnd = itemModEnd.diff(
461-
itemModEnd.endOf("day"),
462-
"minute",
463-
)
464-
dmin -= daysCount * diffToDayEnd
465-
}
466-
}
467-
let width = dmin / timeSteps*/
468-
469-
// check if this is the last time slot of the day
470-
//width = endSlot + 1 - startSlot - (left + width)
471-
//width = endSlot - startSlot + width - left
472-
473463
if (width <= 0) {
474464
// this should not happen, but if it does, we need to log it to find the error
475465
console.error(
476-
"LPTimeTable - item with negative width found:",
466+
"TimeTable - item with negative/zero width found:",
477467
width,
478468
item,
479469
startSlot,
@@ -486,6 +476,24 @@ export function getLeftAndWidth(
486476
)
487477
}
488478

479+
/*console.log(
480+
"LEFT",
481+
left,
482+
item,
483+
itemModStart,
484+
slotStart,
485+
timeSlotMinutes,
486+
slotStart,
487+
"DAY STARTDIFF",
488+
dayStartDiff,
489+
"STARTSUM",
490+
startSum,
491+
"TFD",
492+
timeFrameDay,
493+
"SLOTSTARTDIFF",
494+
slotStartDiff,
495+
)*/
496+
489497
return { left, width }
490498
}
491499

0 commit comments

Comments
 (0)