diff --git a/Frontend/src/app/components/datepicker/datepicker.component.ts b/Frontend/src/app/components/datepicker/datepicker.component.ts index 3d74214..0913b61 100644 --- a/Frontend/src/app/components/datepicker/datepicker.component.ts +++ b/Frontend/src/app/components/datepicker/datepicker.component.ts @@ -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'; + } } }