time picker closing fix
This commit is contained in:
@@ -351,7 +351,6 @@
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
// NEW: Generate grouped time slots (available as individual buttons, unavailable as grouped blocks)
|
|
||||||
function generateGroupedTimeSlots(
|
function generateGroupedTimeSlots(
|
||||||
duration: number,
|
duration: number,
|
||||||
date: CalendarDate | undefined
|
date: CalendarDate | undefined
|
||||||
@@ -429,17 +428,32 @@
|
|||||||
startTime: timeStr,
|
startTime: timeStr,
|
||||||
endTime: slotEndTime
|
endTime: slotEndTime
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If this available slot ends at or after closing time, break out early
|
||||||
|
// to avoid generating unnecessary slots
|
||||||
|
if (timeToMinutes(slotEndTime) >= endTotalMinutes) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Start or continue unavailable group
|
// Start or continue unavailable group
|
||||||
if (currentUnavailableStart === null) {
|
if (currentUnavailableStart === null) {
|
||||||
currentUnavailableStart = timeStr;
|
currentUnavailableStart = timeStr;
|
||||||
}
|
}
|
||||||
// Continue the group - we'll close it when we hit an available slot or end
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close any remaining unavailable group at the end of the day
|
// Close any remaining unavailable group at the end of the day
|
||||||
|
// BUT only if there are no available slots that already reach closing time
|
||||||
if (currentUnavailableStart !== null) {
|
if (currentUnavailableStart !== null) {
|
||||||
|
const lastAvailableSlot = groupedSlots.filter((s) => s.type === 'available').pop();
|
||||||
|
const lastAvailableEnd = lastAvailableSlot ? timeToMinutes(lastAvailableSlot.endTime) : 0;
|
||||||
|
|
||||||
|
// Only add the final unavailable group if:
|
||||||
|
// 1. It actually contains some time before closing
|
||||||
|
// 2. No available slot already reaches closing time
|
||||||
|
const unavailableStartMinutes = timeToMinutes(currentUnavailableStart);
|
||||||
|
|
||||||
|
if (unavailableStartMinutes < endTotalMinutes && lastAvailableEnd < endTotalMinutes) {
|
||||||
groupedSlots.push({
|
groupedSlots.push({
|
||||||
type: 'unavailable',
|
type: 'unavailable',
|
||||||
startTime: currentUnavailableStart,
|
startTime: currentUnavailableStart,
|
||||||
@@ -447,10 +461,17 @@
|
|||||||
isGrouped: true
|
isGrouped: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return groupedSlots;
|
return groupedSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper: Convert time string to total minutes
|
||||||
|
function timeToMinutes(time: string): number {
|
||||||
|
const [hours, minutes] = time.split(':').map(Number);
|
||||||
|
return hours * 60 + minutes;
|
||||||
|
}
|
||||||
|
|
||||||
// Helper: Calculate the previous 15-minute time slot
|
// Helper: Calculate the previous 15-minute time slot
|
||||||
function calculatePreviousTime(time: string): string {
|
function calculatePreviousTime(time: string): string {
|
||||||
const [hours, minutes] = time.split(':').map(Number);
|
const [hours, minutes] = time.split(':').map(Number);
|
||||||
@@ -462,7 +483,6 @@
|
|||||||
return `${String(prevHours).padStart(2, '0')}:${String(prevMinutes).padStart(2, '0')}`;
|
return `${String(prevHours).padStart(2, '0')}:${String(prevMinutes).padStart(2, '0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEW: Generate available time slots within available segments
|
|
||||||
function generateAvailableTimeSlots(duration: number, date: CalendarDate | undefined): string[] {
|
function generateAvailableTimeSlots(duration: number, date: CalendarDate | undefined): string[] {
|
||||||
if (!date || !workingHours || !availableHours) {
|
if (!date || !workingHours || !availableHours) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
Reference in New Issue
Block a user