Saving week and other preferences in localstorage so they are persistent
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2021-10-03 10:28:36 +02:00
parent d7c9fc9265
commit 7224a732e2

View File

@ -28,6 +28,7 @@ export class DatepickerComponent implements OnInit {
ngOnInit(): void {
this.fillDatePickers();
this.getDetailsFromLocalStorage();
this.handleDateChange();
}
@ -128,6 +129,7 @@ export class DatepickerComponent implements OnInit {
handleDateChange(): void {
let mondayDate = this.findMondayInWeek(this.selectedYear, this.selectedMonth, this.selectedDay);
this.selectedMonday.emit(mondayDate);
this.saveDetailsToLocalStorage();
}
/**
@ -208,5 +210,36 @@ export class DatepickerComponent implements OnInit {
this.switchDeletedBtnClass = 'show';
this.showingDeletedBtnText = 'Showing deleted events';
}
this.saveDetailsToLocalStorage();
}
saveDetailsToLocalStorage() {
localStorage.setItem('has_saved_details', 'true');
localStorage.setItem('selected_year', this.selectedYear);
localStorage.setItem('selected_month', this.selectedMonth);
localStorage.setItem('selected_day', this.selectedDay);
localStorage.setItem('show_deleted', this.internalShowDeletedEvents.toString());
}
getDetailsFromLocalStorage() {
if((localStorage.getItem('has_saved_details') ?? 'false') === 'true') {
this.selectedYear = localStorage.getItem('selected_year')!;
this.selectedMonth = localStorage.getItem('selected_month')!;
this.selectedDay = localStorage.getItem('selected_day')!;
this.internalShowDeletedEvents = localStorage.getItem('show_deleted')! === 'true';
this.showDeletedEvents.emit(this.internalShowDeletedEvents);
this.checkShowDeletedEventsBtn();
}
}
checkShowDeletedEventsBtn() {
if(this.internalShowDeletedEvents) {
this.switchDeletedBtnClass = 'show';
this.showingDeletedBtnText = 'Showing deleted events';
} else {
this.switchDeletedBtnClass = 'hide';
this.showingDeletedBtnText = 'Deleted events hidden';
}
}
}