From fad646853f4ed05258e93824ce9fa0389b26bf92 Mon Sep 17 00:00:00 2001 From: Saade Date: Sun, 26 Jun 2022 22:20:35 -0300 Subject: [PATCH] feat: refresh calendar events --- resources/views/fullcalendar.blade.php | 5 +++++ src/Widgets/Concerns/CanRefreshEvents.php | 11 +++++++++++ src/Widgets/FullCalendarWidget.php | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 src/Widgets/Concerns/CanRefreshEvents.php diff --git a/resources/views/fullcalendar.blade.php b/resources/views/fullcalendar.blade.php index 7c0e144..1bc6b9b 100644 --- a/resources/views/fullcalendar.blade.php +++ b/resources/views/fullcalendar.blade.php @@ -18,6 +18,11 @@ )); calendar.render(); + + window.addEventListener("fullcalendar::refresh", event => { + calendar.removeAllEvents(); + event.detail.data.map(event => calendar.addEvent(event)); + }); })'> diff --git a/src/Widgets/Concerns/CanRefreshEvents.php b/src/Widgets/Concerns/CanRefreshEvents.php new file mode 100644 index 0000000..f5e9a75 --- /dev/null +++ b/src/Widgets/Concerns/CanRefreshEvents.php @@ -0,0 +1,11 @@ +dispatchBrowserEvent('fullcalendar::refresh', ['data' => $this->getViewData()]); + } +} diff --git a/src/Widgets/FullCalendarWidget.php b/src/Widgets/FullCalendarWidget.php index c9354d3..012d7c2 100644 --- a/src/Widgets/FullCalendarWidget.php +++ b/src/Widgets/FullCalendarWidget.php @@ -4,11 +4,13 @@ use Filament\Widgets\Widget; use Illuminate\View\View; +use Saade\FilamentFullCalendar\Widgets\Concerns\CanRefreshEvents; use Saade\FilamentFullCalendar\Widgets\Concerns\FiresEvents; use Saade\FilamentFullCalendar\Widgets\Concerns\UsesConfig; class FullCalendarWidget extends Widget { + use CanRefreshEvents; use FiresEvents; use UsesConfig;