From 7fbe17309f5d9ecb72411a657bae32fac8d21962 Mon Sep 17 00:00:00 2001 From: Fauzie Date: Fri, 2 Sep 2022 10:21:21 +0700 Subject: [PATCH 1/2] Delete fullcalendar-widget.png:Zone.Identifier Fixes unable to clone repo on Windows. --- art/fullcalendar-widget.png:Zone.Identifier | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 art/fullcalendar-widget.png:Zone.Identifier diff --git a/art/fullcalendar-widget.png:Zone.Identifier b/art/fullcalendar-widget.png:Zone.Identifier deleted file mode 100644 index a831910..0000000 --- a/art/fullcalendar-widget.png:Zone.Identifier +++ /dev/null @@ -1,3 +0,0 @@ -[ZoneTransfer] -LastWriterPackageFamilyName=Microsoft.ScreenSketch_8wekyb3d8bbwe -ZoneId=3 From 697f654134b573a4c71d9e126b01906f280b99de Mon Sep 17 00:00:00 2001 From: Fauzie Date: Fri, 2 Sep 2022 12:19:48 +0700 Subject: [PATCH 2/2] feat: save state --- resources/views/fullcalendar.blade.php | 20 +++++++++++++++++++- src/Widgets/FullCalendarWidget.php | 6 +++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/resources/views/fullcalendar.blade.php b/resources/views/fullcalendar.blade.php index 50ee074..d7aad72 100644 --- a/resources/views/fullcalendar.blade.php +++ b/resources/views/fullcalendar.blade.php @@ -68,6 +68,16 @@ @endif } + @if($this->config('saveState', false)) + const key = "{{ $this->getKey() }}"; + const initialView = + localStorage.getItem("fullcalendar.view." + key) ?? + @json($this->config('initialView')); + const initialDate = + localStorage.getItem("fullcalendar.date." + key) ?? + @json($this->config('initialDate')); + @endif + const calendar = new FullCalendar.Calendar($el, { ...config, locale, @@ -79,7 +89,15 @@ eventSources:[ { events }, fetchEvents - ] + ], + @if($this->config('saveState', false)) + initialView: initialView ?? undefined, + initialDate: initialDate ?? undefined, + datesSet: function ({start, view}) { + localStorage.setItem("fullcalendar.view." + key, view.type); + localStorage.setItem("fullcalendar.date." + key, start.toISOString()); + }, + @endif }); calendar.render(); diff --git a/src/Widgets/FullCalendarWidget.php b/src/Widgets/FullCalendarWidget.php index c563801..a8a5d0e 100644 --- a/src/Widgets/FullCalendarWidget.php +++ b/src/Widgets/FullCalendarWidget.php @@ -17,7 +17,6 @@ class FullCalendarWidget extends Widget implements HasForms use InteractsWithForms, CanManageEvents { CanManageEvents::getForms insteadof InteractsWithForms; } - use CanRefreshEvents; use CanFetchEvents; use FiresEvents; @@ -39,4 +38,9 @@ public function render(): View 'events' => $this->getViewData(), ]); } + + public function getKey(): string + { + return $this->key ?? 'default'; + } }