This commit is contained in:
1 parent
5a34160ab2
commit
578aafbf91
4 files changed
+256
-6
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { SelectableDayType, VacDay } from './calendar-service';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -51,6 +52,26 @@ export class UserInputService {
|
||||
readonly remainingVacationDaysSignal = signal<VacDay[]>([]);
|
||||
readonly computeTriggerSignal = signal(0);
|
||||
|
||||
public updateBalances(updater: (balances: VacDay[]) => VacDay[]): void {
|
||||
this.vacationNumberSignal.update(updater);
|
||||
try {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
// Store calendar dates, so restoring them does not depend on a UTC offset.
|
||||
const balances = this.vacationNumberSignal().map((balance) => ({
|
||||
id: balance.id,
|
||||
type: balance.type,
|
||||
numberOfDays: balance.numberOfDays,
|
||||
availableDate: balance.availableDate
|
||||
? dayjs(balance.availableDate).format('YYYY-MM-DD')
|
||||
: undefined,
|
||||
expiryDate: dayjs(balance.expiryDate).format('YYYY-MM-DD'),
|
||||
}));
|
||||
localStorage.setItem('leaveBalances', JSON.stringify(balances));
|
||||
} catch (error) {
|
||||
console.warn('Failed to save leave balances to localStorage.', error);
|
||||
}
|
||||
}
|
||||
|
||||
public requestComputation(): void {
|
||||
this.computeTriggerSignal.update((count) => count + 1);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user