Use localstorage to remeber current view

This commit is contained in:
Edward Betts 2023-11-24 14:40:28 +00:00
parent 89e08cf61e
commit ec0f2cce7e

View file

@ -27,6 +27,16 @@
import listPlugin from '@fullcalendar/list'
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() {
const calendarEl = document.getElementById('calendar')
const calendar = new Calendar(calendarEl, {
@ -34,7 +44,10 @@
plugins: [dayGridPlugin, timeGridPlugin, listPlugin ],
themeSystem: 'bootstrap5',
firstDay: 1,
initialView: 'dayGridMonth',
initialView: getSavedView(),
viewDidMount: function(info) {
saveView(info.view.type);
},
headerToolbar: {
left: 'prev,next today',
center: 'title',
@ -54,6 +67,7 @@
})
calendar.render()
})
</script>
</head>