refactor(scheduling): extract appendDays helper and document index key stability
Replace duplicated init-or-concat logic in handleRequestMoreDates with a shared appendDays function. Add a comment clarifying that inshopTimeSlots_N keys are safe to use by index because provider order is fixed after beforeRouteEnter.
This commit is contained in:
parent
d72eae4ea6
commit
996ad3cc58
1 changed files with 18 additions and 20 deletions
|
|
@ -88,6 +88,20 @@ function toDateString(offsetDays, base = new Date()) {
|
|||
const SCHEDULE_FETCH_DAYS = 15;
|
||||
const SCHEDULING_RADIO_GROUP_NAME = "schedulingTimeSlot";
|
||||
|
||||
/**
|
||||
* Appends days from newSlots into entry.timeSlots, initializing it if absent.
|
||||
* @param {{ timeSlots: { days: any[] } | null }} entry
|
||||
* @param {{ days: any[] } | null | undefined} newSlots
|
||||
*/
|
||||
function appendDays(entry, newSlots) {
|
||||
if (!newSlots) return;
|
||||
if (!entry.timeSlots) {
|
||||
entry.timeSlots = newSlots;
|
||||
} else {
|
||||
entry.timeSlots.days = [...(entry.timeSlots.days ?? []), ...(newSlots.days ?? [])];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise for inshop time slots for a single provider.
|
||||
* @param {{ startDate: string, endDate: string, providerNumber: string, pageNameToLog: string }} params
|
||||
|
|
@ -326,29 +340,13 @@ export default {
|
|||
|
||||
const resultMap = await settleAllPromises(promiseResultMap);
|
||||
|
||||
// Provider order is fixed after beforeRouteEnter, so index keys are stable.
|
||||
this.inShopProvidersAndTimeslots.forEach((entry, index) => {
|
||||
const newSlots = resultMap[`inshopTimeSlots_${index}`];
|
||||
if (!newSlots) return;
|
||||
if (!entry.timeSlots) {
|
||||
entry.timeSlots = newSlots;
|
||||
} else {
|
||||
entry.timeSlots.days = [
|
||||
...(entry.timeSlots.days ?? []),
|
||||
...(newSlots.days ?? []),
|
||||
];
|
||||
}
|
||||
appendDays(entry, resultMap[`inshopTimeSlots_${index}`]);
|
||||
});
|
||||
|
||||
if (this.mobileProviderAndTimeSlot && resultMap.mobileTimeSlots) {
|
||||
const newSlots = resultMap.mobileTimeSlots;
|
||||
if (!this.mobileProviderAndTimeSlot.timeSlots) {
|
||||
this.mobileProviderAndTimeSlot.timeSlots = newSlots;
|
||||
} else {
|
||||
this.mobileProviderAndTimeSlot.timeSlots.days = [
|
||||
...(this.mobileProviderAndTimeSlot.timeSlots.days ?? []),
|
||||
...(newSlots.days ?? []),
|
||||
];
|
||||
}
|
||||
if (this.mobileProviderAndTimeSlot) {
|
||||
appendDays(this.mobileProviderAndTimeSlot, resultMap.mobileTimeSlots);
|
||||
}
|
||||
|
||||
this.datePickerEndDate = newEndDate;
|
||||
|
|
|
|||
Loading…
Reference in a new issue