Skip to content

Commit

Permalink
Merge pull request #100 from linked-planet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
marcus-wishes authored Dec 17, 2024
2 parents e444020 + dd21031 commit 5a3b474
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function useOptions({
.map((it) => Number.parseInt(it) ?? 0)
let end = dayjs().hour(endHourMin[0]).minute(endHourMin[1])
let curr = dayjs().hour(startHourMin[0]).minute(startHourMin[1])
if (end.isSame(curr)) {
if (end.isSame(curr) || end.isBefore(curr)) {
end = end.add(1, "day")
}

Expand Down
27 changes: 20 additions & 7 deletions library/src/components/timetable/TimeTableRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,24 @@ export default function TimeTableRows<
`Timetable - shorten rendered elements array from ${groupRowsRendered.length} to ${groupRows.size}`,
)
setGroupRowsRendered(groupRowsRendered.slice(0, groupRows.size))
for (const changedG of changedGroupRows.current) {
if (changedG > groupRows.size - 1) {
changedGroupRows.current.delete(changedG)
}
}
for (const renderedG of renderedGroups.current) {
if (renderedG > groupRows.size - 1) {
renderedGroups.current.delete(renderedG)
}
}
refCollection.current.length = groupRows.size
if (renderGroupRangeRef.current[0] > groupRows.size - 1) {
renderGroupRangeRef.current = [0, groupRows.size - 1]
setRenderGroupRange([0, groupRows.size - 1])
}
if (refCollection.current.length < groupRows.size) {
refCollection.current.length = groupRows.size
}
}

// determine when new ones start
Expand Down Expand Up @@ -398,18 +415,11 @@ export default function TimeTableRows<
changedGroupRows.current.delete(changedG)
}
}
for (const renderedG of renderedGroups.current) {
if (renderedG > keys.length - 1) {
// delete obsolete change
renderedGroups.current.delete(renderedG)
}
}

if (updateCounter) {
console.log(
`TimeTable - group rows require updated rendering ${updateCounter}, with first ${changedFound}`,
renderGroupRangeRef.current,
currentGroupRowsRef.current.size,
groupRows.size,
)
} else {
Expand Down Expand Up @@ -557,6 +567,9 @@ export default function TimeTableRows<
)
++counter
}
if (groupRowsRendered.length > currentGroupRowsRef.current.size) {
groupRowsRendered.length = currentGroupRowsRef.current.size
}
rateLimiterIntersection(handleIntersections)
return groupRowsRendered
})
Expand Down
54 changes: 31 additions & 23 deletions library/src/components/timetable/timeTableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,19 @@ export function getLeftAndWidth(
}

const slotStart = slotsArray[startSlot]
const ddaysDiff = itemModStart.diff(slotStart, "day")
const startDiffDays = ddaysDiff * timeFrameDay.oneDayMinutes

const dayStartDiff =
viewType === "hours"
? 0
: timeFrameDay.startHour * 60 + timeFrameDay.startMinute
const startSum = startDiffDays + dayStartDiff

const slotStartDiff = itemModStart.diff(slotStart, "minute")

const left = (slotStartDiff - startSum) / timeSlotMinutes

const dstartMin = itemModStart.diff(slotStart, "minute")
let left = dstartMin / timeSlotMinutes
if (left < 0) {
console.error(
"LPTimeTable - item with negative left found:",
Expand All @@ -445,35 +455,15 @@ export function getLeftAndWidth(
slotsArray,
timeSlotMinutes,
)
// if the start is before the time slot, we need to set the left to 0
left = 0
}

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

/*let dmin = itemModEnd.diff(slotsArray[endSlot], "minute")
// 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
if (viewType !== "hours") {
const daysCount = Math.floor(dmin / (26 * 60))
if (daysCount > 0) {
const diffToDayEnd = itemModEnd.diff(
itemModEnd.endOf("day"),
"minute",
)
dmin -= daysCount * diffToDayEnd
}
}
let width = dmin / timeSteps*/

// check if this is the last time slot of the day
//width = endSlot + 1 - startSlot - (left + width)
//width = endSlot - startSlot + width - left

if (width <= 0) {
// this should not happen, but if it does, we need to log it to find the error
console.error(
"LPTimeTable - item with negative width found:",
"TimeTable - item with negative/zero width found:",
width,
item,
startSlot,
Expand All @@ -486,6 +476,24 @@ export function getLeftAndWidth(
)
}

/*console.log(
"LEFT",
left,
item,
itemModStart,
slotStart,
timeSlotMinutes,
slotStart,
"DAY STARTDIFF",
dayStartDiff,
"STARTSUM",
startSum,
"TFD",
timeFrameDay,
"SLOTSTARTDIFF",
slotStartDiff,
)*/

return { left, width }
}

Expand Down

0 comments on commit 5a3b474

Please sign in to comment.