From 7224a732e2dca09502554ffdf7287476584d56f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sun, 3 Oct 2021 10:28:36 +0200 Subject: [PATCH] Saving week and other preferences in localstorage so they are persistent --- .../datepicker/datepicker.component.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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'; + } } }