Fix setTimeout async anti-pattern in calendar-year component #128

Merged
admin-backup merged 2 commits from copilot/sub-pr-49 into THoguet/issue16 2025-11-18 00:26:19 +01:00
@@ -41,23 +41,25 @@ export class CalendarYear {
console.log('Optimizing vacations with data:', vacationData); console.log('Optimizing vacations with data:', vacationData);
this.isLoading.set(true); this.isLoading.set(true);
this.loadingProgress.set(0); this.loadingProgress.set(0);
// Simulate server-side calculation with a small delay // Defer execution to allow UI to update
setTimeout(async () => { queueMicrotask(() => {
if (this.selectedDates) { void (async () => {
// Create a copy to avoid mutating the original signal data if (this.selectedDates) {
const remainingDays = await this.selectedDates.optimizeVacations( // Create a copy to avoid mutating the original signal data
{ ...vacationData }, const remainingDays = await this.selectedDates.optimizeVacations(
this.calendarSettingsService, { ...vacationData },
this.calendarService, this.calendarSettingsService,
(progress: number) => { this.calendarService,
this.loadingProgress.set(progress); (progress: number) => {
}, this.loadingProgress.set(progress);
); },
// Update the remaining vacation days signal );
this.userInput.remainingVacationDaysSignal.set(remainingDays); // Update the remaining vacation days signal
} this.userInput.remainingVacationDaysSignal.set(remainingDays);
this.isLoading.set(false); }
}, 1); this.isLoading.set(false);
})();
});
}); });
} }