Persist in localStorage

This commit is contained in:
Leo Vasanko committed 2025-08-22 20:16:39 -06:00
1 parent 407e87e0f9
commit d46aaa6106
5 files changed
+53 -7

No files matched your search

+19 -3
View File
@@ -7,7 +7,7 @@ const MAX_YEAR = 2100
export const useCalendarStore = defineStore('calendar', {
state: () => ({
today: toLocalString(new Date()),
now: new Date(),
now: new Date().toISOString(), // store as ISO string
events: new Map(), // Map of date strings to arrays of events
weekend: getLocaleWeekendDays(),
config: {
@@ -26,8 +26,9 @@ export const useCalendarStore = defineStore('calendar', {
actions: {
updateCurrentDate() {
this.now = new Date()
const today = toLocalString(this.now)
const d = new Date()
this.now = d.toISOString()
const today = toLocalString(d)
if (this.today !== today) {
this.today = today
}
@@ -468,4 +469,19 @@ export const useCalendarStore = defineStore('calendar', {
// NOTE: legacy dynamic getEventById for synthetic occurrences removed.
},
persist: {
key: 'calendar-store',
storage: localStorage,
paths: ['today', 'events', 'config'],
serializer: {
serialize(value) {
return JSON.stringify(value, (_k, v) =>
v instanceof Map ? { __map: true, data: [...v] } : v,
)
},
deserialize(value) {
return JSON.parse(value, (_k, v) => (v && v.__map ? new Map(v.data) : v))
},
},
},
})