Skip to content

Commit

Permalink
Fix date init from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvonen committed Jan 30, 2024
1 parent 50c8822 commit 898fe81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/__tests__/calendarExport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe('useCalendarExport', () => {
});

const createTestComponent = (settings: ScheduleSettings, weeks: Week[]) => {
scheduleStore.$patch({
settings,
weeks,
scheduleStore.$patch((state) => {
state.settings = settings;
state.weeks = weeks;
});
const promise: Promise<CalendarEvent[]> = new Promise((resolve) => {
mount({
Expand Down
9 changes: 9 additions & 0 deletions src/stores/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export const useScheduleStore = defineStore('schedule', () => {
// State refs
const settings = useStorage('getfit-settings', getEmptySchedule(), localStorage, {
mergeDefaults: true,
serializer: {
read: (v: any) => v ? JSON.parse(v, (key, value) => {
if (key === 'startDate' && value) {
return DateTime.fromISO(value).toJSDate();
}
return value;
}) : null,
write: (v: any) => JSON.stringify(v),
},
});

const weeks = useStorage('getfit-schedule', [] as Week[], localStorage, {mergeDefaults: true});
Expand Down

0 comments on commit 898fe81

Please sign in to comment.