Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71da817

Browse files
PGLongoclaude
andcommitted
fix(stores): resolve time slots loading error when localStorage is empty
- Always initialize currentDate before accessing toISOString() - Remove unused defaultGridConfig variable - Fix error "Cannot read properties of undefined" on first load - Ensure proper fallback when no localStorage data exists 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5e85dc9 commit 71da817

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

app/stores/useTimeSlots.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ export const useTimeSlotsStore = defineStore('timeSlots', () => {
1111
// Available dates for navigation
1212
const availableDates = ref<string[]>([])
1313

14-
// Default time grid configuration (using settings store values)
15-
const defaultGridConfig: TimeGridConfig = {
16-
startHour: 9, // 9:00
17-
endHour: 18, // 18:00
18-
slotDuration: 30, // 30 minuti
19-
includedDays: [1, 2, 3, 4, 5] // Lun-Ven
20-
}
14+
// Note: Grid config is managed by settings store, no default needed here
2115

2216
// Dynamic grid config that updates with settings
2317
const gridConfig = computed((): TimeGridConfig => ({
@@ -534,6 +528,11 @@ export const useTimeSlotsStore = defineStore('timeSlots', () => {
534528
const loadTimeSlots = (): void => {
535529
if (typeof window !== 'undefined') {
536530
try {
531+
// Always ensure currentDate is set first
532+
if (!currentDate.value) {
533+
currentDate.value = new Date()
534+
}
535+
537536
const saved = localStorage.getItem('braindump-timeslots')
538537
if (saved) {
539538
const parsedData = JSON.parse(saved)
@@ -552,9 +551,8 @@ export const useTimeSlotsStore = defineStore('timeSlots', () => {
552551
currentDate.value = new Date(parsedData.currentDate)
553552
}
554553

555-
if (parsedData.gridConfig) {
556-
gridConfig.value = { ...defaultGridConfig, ...parsedData.gridConfig }
557-
}
554+
// Note: gridConfig is computed from settings store, so no need to restore it
555+
// The settings store handles its own persistence
558556
}
559557

560558
// Only generate slots if we don't have any for the current date
@@ -572,6 +570,10 @@ export const useTimeSlotsStore = defineStore('timeSlots', () => {
572570

573571
} catch (error) {
574572
console.error('Error loading time slots from localStorage:', error)
573+
// Ensure currentDate is set even on error
574+
if (!currentDate.value) {
575+
currentDate.value = new Date()
576+
}
575577
generateSlotsForDate(currentDate.value)
576578
}
577579
}

0 commit comments

Comments
 (0)