Skip to content

Commit

Permalink
Merge pull request #78 from linked-planet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
marcus-wishes authored Nov 26, 2024
2 parents 85ec1d4 + ca28322 commit 50aae7b
Show file tree
Hide file tree
Showing 16 changed files with 1,179 additions and 711 deletions.
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

0 comments on commit 50aae7b

Please sign in to comment.