Use localstorage to remeber current view
This commit is contained in:
parent
89e08cf61e
commit
ec0f2cce7e
|
@ -27,6 +27,16 @@
|
||||||
import listPlugin from '@fullcalendar/list'
|
import listPlugin from '@fullcalendar/list'
|
||||||
import gbLocale from '@fullcalendar/core/locales/en-gb';
|
import gbLocale from '@fullcalendar/core/locales/en-gb';
|
||||||
|
|
||||||
|
// Function to save the current view to local storage
|
||||||
|
function saveView(view) {
|
||||||
|
localStorage.setItem('fullCalendarDefaultView', view);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to get the saved view from local storage
|
||||||
|
function getSavedView() {
|
||||||
|
return localStorage.getItem('fullCalendarDefaultView') || 'dayGridMonth';
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const calendarEl = document.getElementById('calendar')
|
const calendarEl = document.getElementById('calendar')
|
||||||
const calendar = new Calendar(calendarEl, {
|
const calendar = new Calendar(calendarEl, {
|
||||||
|
@ -34,7 +44,10 @@
|
||||||
plugins: [dayGridPlugin, timeGridPlugin, listPlugin ],
|
plugins: [dayGridPlugin, timeGridPlugin, listPlugin ],
|
||||||
themeSystem: 'bootstrap5',
|
themeSystem: 'bootstrap5',
|
||||||
firstDay: 1,
|
firstDay: 1,
|
||||||
initialView: 'dayGridMonth',
|
initialView: getSavedView(),
|
||||||
|
viewDidMount: function(info) {
|
||||||
|
saveView(info.view.type);
|
||||||
|
},
|
||||||
headerToolbar: {
|
headerToolbar: {
|
||||||
left: 'prev,next today',
|
left: 'prev,next today',
|
||||||
center: 'title',
|
center: 'title',
|
||||||
|
@ -54,6 +67,7 @@
|
||||||
})
|
})
|
||||||
calendar.render()
|
calendar.render()
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in a new issue