From ec0f2cce7eb2a9c24c8186b16e7233085e870801 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 24 Nov 2023 14:40:28 +0000 Subject: [PATCH] Use localstorage to remeber current view --- templates/index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 4b84afc..7e700df 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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() }) +