Skip to content
Merged

Dev #78

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e04848
work on time table row rendering performance
marcus-wishes Nov 11, 2024
7b8bd1e
Merge commit 'f30ef0fcb422509349daf56a6ad5ba2895f65404' into dev
marcus-wishes Nov 11, 2024
992b558
time table - use of debounced intersection
marcus-wishes Nov 11, 2024
4938142
time table rendering update
marcus-wishes Nov 11, 2024
2acda25
WIP
marcus-wishes Nov 12, 2024
57d2fda
Merge commit '9d1762322941a3f547375d4e5be83794b3523944' into dev
marcus-wishes Nov 13, 2024
69f781b
time table batch rendering WIP
marcus-wishes Nov 13, 2024
6d1ea85
Merge branch 'main' into dev
marcus-wishes Nov 13, 2024
63456df
timetable - viewport based rendering 1
marcus-wishes Nov 14, 2024
e4b9b37
timetable - viewport based batch rendering 2
marcus-wishes Nov 14, 2024
d1809ed
timetable - rendering
marcus-wishes Nov 14, 2024
bafc7a5
time table diff rendering
marcus-wishes Nov 15, 2024
e3d9d51
time table - group row updates
marcus-wishes Nov 15, 2024
d061179
Merge branch 'main' into dev
marcus-wishes Nov 19, 2024
1acf774
showcase sources updated
marcus-wishes Nov 19, 2024
99d263a
added loading spinner classname to loading button
marcus-wishes Nov 19, 2024
60d117e
made loadingSpinnerClassName optional, removed some comments from the…
marcus-wishes Nov 19, 2024
9339027
select show case - added isDisabled and isFixed examples
marcus-wishes Nov 20, 2024
6f6bba3
time table row update
marcus-wishes Nov 20, 2024
b2beb7b
Time Table - updating finally seems to work
marcus-wishes Nov 21, 2024
4b44605
time table - fixed import, avoided unnecessary re-renderings
marcus-wishes Nov 21, 2024
2323768
time table - fixed flicker
marcus-wishes Nov 25, 2024
5a595f4
time table, fixed now bar
marcus-wishes Nov 25, 2024
f020685
time table - fixed row rendering too many cols in first render after …
marcus-wishes Nov 26, 2024
729ffed
time table - fixed nowbar height calc
marcus-wishes Nov 26, 2024
0c855c8
time table - reenabled updates
marcus-wishes Nov 26, 2024
ca28322
time table - refactored update of groups
marcus-wishes Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"request": "attach",
"name": "Attach"
},
{
"type": "chrome",
"request": "launch",
Expand Down
10 changes: 6 additions & 4 deletions library/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ export const LoadingButton = ({
iconAfter,
iconBefore,
children,
loadingSpinnerClassName,
...props
}: ButtonProps & { loading: boolean }) => {
}: ButtonProps & { loading: boolean; loadingSpinnerClassName?: string }) => {
return (
<Button
iconAfter={!loading && iconAfter}
Expand All @@ -213,11 +214,12 @@ export const LoadingButton = ({
{loading && (
<div className="absolute inset-0 flex items-center justify-center">
<LoadingSpinner
className={
className={twMerge(
loadingSpinnerClassNames[
props.appearance ?? "default"
]
}
],
loadingSpinnerClassName,
)}
/>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion library/src/components/ToastFlag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function CloseButton({
type="button"
data-id="flag-close-button"
ref={ref}
className={`cursor-pointer mb-auto ${
className={`cursor-pointer mb-auto bg-transparent border-none ${
inverted ? "text-text" : "text-text-inverse"
}`}
onClick={closeToast}
Expand Down
63 changes: 45 additions & 18 deletions library/src/components/timetable/TimeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import {
import {
initAndUpdateTimeTableConfigStore,
type TimeFrameDay,
useTTCSlotsArray,
useTTCTimeFrameOfDay,
useTTCTimeSlotMinutes,
} from "./TimeTableConfigStore"
import { TimeTableIdentProvider } from "./TimeTableIdentContext"
import { initAndUpdateTimeTableComponentStore } from "./TimeTableComponentStore"
Expand Down Expand Up @@ -194,6 +191,12 @@ export interface LPTimeTableProps<
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => JSX.Element
header: (props: CustomHeaderRowHeaderProps<G, I>) => JSX.Element
}

/**
* renderBatch tells how many groups are calculated in one step and rendered. This is useful for large time tables, where the rendering takes a long time.
* @default 10
*/
renderBatch?: number
}

const nowbarUpdateIntervall = 1000 * 60 // 1 minute
Expand All @@ -214,6 +217,8 @@ export default function LPTimeTable<
)
}

export let timeTableGroupRenderBatchSize = 10

/**
* The LPTimeTable depends on the localization messages. It needs to be wrapped in an
* @returns
Expand Down Expand Up @@ -252,12 +257,15 @@ const LPTimeTableImpl = <G extends TimeTableGroup, I extends TimeSlotBooking>({
className,
style,
customHeaderRow,
renderBatch = timeTableGroupRenderBatchSize,
}: LPTimeTableProps<G, I>) => {
// if we have viewType of days, we need to round the start and end date to the start and end of the day
const { setMessage, translatedMessage } = useTimeTableMessage(
!disableMessages,
)

timeTableGroupRenderBatchSize = renderBatch

// change on viewType
// biome-ignore lint/correctness/useExhaustiveDependencies: just remove the message is props change
useEffect(() => {
Expand Down Expand Up @@ -293,33 +301,32 @@ const LPTimeTableImpl = <G extends TimeTableGroup, I extends TimeSlotBooking>({
isCellDisabled,
)

const timeFrameDay = useTTCTimeFrameOfDay(storeIdent)
const timeSlotMinutes = useTTCTimeSlotMinutes(storeIdent)

initAndUpdateTimeTableSelectionStore(
storeIdent,
defaultSelectedTimeRange,
selectedTimeRange,
onTimeRangeSelected,
)

const slotsArray = useTTCSlotsArray(storeIdent)
if (!slotsArray || slotsArray.length === 0) {
console.warn(
"LPTimeTable - no slots array, or slots array is empty",
slotsArray,
)
return <div>No slots array</div>
}

const {
groupRows,
rowCount,
maxRowCountOfSingleGroup,
itemsOutsideOfDayRange,
itemsWithSameStartAndEnd,
slotsArray,
timeFrameDay,
timeSlotMinutes,
} = useGroupRows(entries)

if (!slotsArray || slotsArray.length === 0) {
console.warn(
"LPTimeTable - no slots array, or slots array is empty",
slotsArray,
)
return <div>No slots array</div>
}

useEffect(() => {
if (!setMessage) return
if (Object.keys(itemsOutsideOfDayRange).length > 0) {
Expand Down Expand Up @@ -531,6 +538,10 @@ const LPTimeTableImpl = <G extends TimeTableGroup, I extends TimeSlotBooking>({
intersectionContainerRef
}
headerRef={tableHeaderRef}
slotsArray={slotsArray}
timeSlotMinutes={timeSlotMinutes}
timeFrameDay={timeFrameDay}
viewType={viewType}
/>
</tbody>
</table>
Expand Down Expand Up @@ -627,11 +638,27 @@ function moveNowBar(
const startSlot = startAndEndSlot.startSlot

// the first row in the body is used for the time slot bars
const tbodyFirstRow = tableBody.children[0] as
let childIdx = 0
let tbodyFirstRow = tableBody.children[childIdx] as
| HTMLTableRowElement
| undefined
// now get the current time slot index element (not -1 because the first empty element for the groups)

// find the first rendered row
while (tbodyFirstRow && tbodyFirstRow.children.length === 0) {
childIdx++
tbodyFirstRow = tableBody.children[childIdx] as
| HTMLTableRowElement
| undefined
}

if (!tbodyFirstRow) {
console.warn(
"LPTimeTable - unable to find time slot row for the now bar",
)
return
}

const slotBar = tbodyFirstRow?.children[startSlot + 1] as
| HTMLDivElement
| undefined
Expand All @@ -652,7 +679,7 @@ function moveNowBar(
nowBar = document.createElement("div")
//nowBar.className = styles.nowBar
nowBar.className =
"absolute opacity-60 bg-orange-bold top-0 bottom-0 z-[1] w-[2px]"
"absolute opacity-60 bg-orange-bold top-0 bottom-0 z-[2] w-[2px]"
slotBar.appendChild(nowBar)
nowBarRef.current = nowBar
}
Expand All @@ -673,7 +700,7 @@ function moveNowBar(

const diffPerc = diffNow / timeSlotMinutes
nowBar.style.left = `${diffPerc * 100}%`
nowBar.style.height = `${tableBody.clientHeight}px`
nowBar.style.height = `${tableBody.getBoundingClientRect().bottom - slotBar.getBoundingClientRect().top}px`

// add orange border
const nowTimeSlotCell = headerTimeSlotCells[startSlot + 1]
Expand Down
20 changes: 0 additions & 20 deletions library/src/components/timetable/TimeTableConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,6 @@ export function useTTCTimeFrameOfDay(ident: string) {
return timeFrameOfDay
}

/**
* returns the current time slots array
*/
export function useTTCSlotsArray(ident: string) {
const slotsArray = useSnapshot(
timeTableConfigStore[ident].basicProperties,
).slotsArray
return slotsArray
}

/**
* returns the time slot minutes and a setter for it
*/
export function useTTCTimeSlotMinutes(ident: string) {
const timeSlotMinutes = useSnapshot(
timeTableConfigStore[ident].basicProperties,
).timeSlotMinutes
return timeSlotMinutes
}

export function useTTCTimeSlotSelectionDisabled(ident: string) {
const timeSlotSelectionDisabled = useSnapshot(
timeTableConfigStore[ident],
Expand Down
Loading