Skip to content

Commit

Permalink
Merge pull request #50 from fauzie811/feature/save-state
Browse files Browse the repository at this point in the history
feat: save state
  • Loading branch information
saade authored Sep 18, 2022
2 parents 39b085d + 697f654 commit e8ef3a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 0 additions & 3 deletions art/fullcalendar-widget.png:Zone.Identifier

This file was deleted.

20 changes: 19 additions & 1 deletion resources/views/fullcalendar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/Widgets/FullCalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class FullCalendarWidget extends Widget implements HasForms
use InteractsWithForms, CanManageEvents {
CanManageEvents::getForms insteadof InteractsWithForms;
}

use CanRefreshEvents;
use CanFetchEvents;
use FiresEvents;
Expand All @@ -39,4 +38,9 @@ public function render(): View
'events' => $this->getViewData(),
]);
}

public function getKey(): string
{
return $this->key ?? 'default';
}
}

0 comments on commit e8ef3a1

Please sign in to comment.