Skip to content
Open
Changes from all commits
Commits
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
27 changes: 22 additions & 5 deletions components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ export default function Calendar(props: Props) {
if (datesType !== 'dates') return
const dates = props.dates
const activeIntervals: string[] = []
// Map from viewer timezone datetime string to meeting-timezone-based index
const intervalIndexMap: Record<string, number> = {}
const newDates: string[] = []
const fallBackHours: number[] = []
const fallBackDates: string[] = []
let minHour, maxHour
let meetingIndex = 0
// get all active intervals
for (const date of dates) {
// get start moment for day
Expand All @@ -83,6 +86,9 @@ export default function Calendar(props: Props) {
if (!fallBackDates.includes(newDate)) fallBackDates.push(newDate)
}
activeIntervals.push(dateTime)
// Map this viewer timezone datetime to the meeting-timezone-based index
intervalIndexMap[dateTime] = meetingIndex
meetingIndex++
// increment base moment
mmt.add(15, 'minutes')
}
Expand All @@ -95,6 +101,7 @@ export default function Calendar(props: Props) {
activeIntervals,
fallBackHours,
fallBackDates,
intervalIndexMap,
}
}, [currentTimezone, datesType, earliest, latest, props.dates, timezone])

Expand All @@ -103,10 +110,13 @@ export default function Calendar(props: Props) {
if (datesType !== 'days') return {}
const days = props.days
const activeIntervals: string[] = []
// Map from viewer timezone datetime string to meeting-timezone-based index
const intervalIndexMap: Record<string, number> = {}
const newDates: string[] = []
const fallBackHours: number[] = []
const fallBackDates: string[] = []
let minHour, maxHour
let meetingIndex = 0
// get all active intervals
for (const day of days) {
for (let hour = earliest; hour < latest; hour++) {
Expand All @@ -129,7 +139,11 @@ export default function Calendar(props: Props) {
// record date and create interval
const newDate = mmt.format('YYYY-MM-DD')
if (!newDates.includes(newDate)) newDates.push(newDate)
activeIntervals.push(mmt.format('YYYY-MM-DD HH:mm'))
const dateTime = mmt.format('YYYY-MM-DD HH:mm')
activeIntervals.push(dateTime)
// Map this viewer timezone datetime to the meeting-timezone-based index
intervalIndexMap[dateTime] = meetingIndex
meetingIndex++
}
}
}
Expand All @@ -141,6 +155,7 @@ export default function Calendar(props: Props) {
activeIntervals,
fallBackHours,
fallBackDates,
intervalIndexMap,
}
}, [currentTimezone, datesType, earliest, latest, props.days, timezone])

Expand All @@ -161,10 +176,10 @@ export default function Calendar(props: Props) {
activeIntervals,
fallBackHours,
fallBackDates,
intervalIndexMap,
} = intervalData
if (minHour === undefined || maxHour === undefined) throw 'undefined hours'
// set up days
let index = 0
const newDays: CalendarDay[] = []
for (const date of newDates) {
const ivs: Interval[] = []
Expand All @@ -185,14 +200,16 @@ export default function Calendar(props: Props) {
`${date} ${hourPadded}:${minutePadded}:00`,
currentTimezone
)
const dateTime = mmt.format('YYYY-MM-DD HH:mm')
const active =
mmt.hour() !== hour
? false // skip invalid spring forward
: i === 1 && !selfFallBack
? false // skip invalid fall back
: activeIntervals.includes(mmt.format('YYYY-MM-DD HH:mm'))
ivs.push({ index: active ? index : -1, hour, minute, active })
if (active) index++
: activeIntervals.includes(dateTime)
// Use the meeting-timezone-based index from the map
const meetingIndex = active ? (intervalIndexMap?.[dateTime] ?? -1) : -1
ivs.push({ index: meetingIndex, hour, minute, active })
}
}
}
Expand Down