@@ -92,7 +92,6 @@ type CalendarCache = {
92
92
googleEvents : WorkspaceCalendarEvent [ ] ;
93
93
dbLastUpdated : number ;
94
94
googleLastUpdated : number ;
95
- isForced : boolean ;
96
95
} ;
97
96
} ;
98
97
@@ -102,7 +101,6 @@ type CacheUpdate = {
102
101
googleEvents ?: WorkspaceCalendarEvent [ ] ;
103
102
dbLastUpdated ?: number ;
104
103
googleLastUpdated ?: number ;
105
- isForced ?: boolean ;
106
104
} ;
107
105
108
106
export const CalendarSyncProvider = ( {
@@ -132,6 +130,7 @@ export const CalendarSyncProvider = ({
132
130
const [ isSyncing , setIsSyncing ] = useState ( false ) ;
133
131
const prevGoogleDataRef = useRef < string > ( '' ) ;
134
132
const prevDatesRef = useRef < string > ( '' ) ;
133
+ const isForcedRef = useRef < boolean > ( false ) ;
135
134
const queryClient = useQueryClient ( ) ;
136
135
137
136
// Helper to generate cache key from dates
@@ -192,18 +191,15 @@ export const CalendarSyncProvider = ({
192
191
googleEvents : [ ] ,
193
192
dbLastUpdated : 0 ,
194
193
googleLastUpdated : 0 ,
195
- isForced : false ,
196
194
} ;
197
195
198
196
return {
199
197
...prev ,
200
198
[ cacheKey ] : {
201
- dbEvents : update . dbEvents || existing . dbEvents ,
202
- googleEvents : update . googleEvents || existing . googleEvents ,
203
- dbLastUpdated : update . dbLastUpdated || existing . dbLastUpdated ,
204
- googleLastUpdated :
205
- update . googleLastUpdated || existing . googleLastUpdated ,
206
- isForced : update . isForced || existing . isForced ,
199
+ dbEvents : update . dbEvents !== undefined ? update . dbEvents : existing . dbEvents ,
200
+ googleEvents : update . googleEvents !== undefined ? update . googleEvents : existing . googleEvents ,
201
+ dbLastUpdated : update . dbLastUpdated !== undefined ? update . dbLastUpdated : existing . dbLastUpdated ,
202
+ googleLastUpdated : update . googleLastUpdated !== undefined ? update . googleLastUpdated : existing . googleLastUpdated ,
207
203
} ,
208
204
} ;
209
205
} ) ;
@@ -224,7 +220,7 @@ export const CalendarSyncProvider = ({
224
220
cachedData ?. dbEvents &&
225
221
cachedData . dbEvents . length > 0 &&
226
222
! isCacheStaleEnhanced ( cachedData . dbLastUpdated , dates ) &&
227
- ! cachedData . isForced
223
+ ! isForcedRef . current
228
224
) {
229
225
setData ( cachedData . dbEvents ) ;
230
226
return cachedData . dbEvents ;
@@ -251,9 +247,11 @@ export const CalendarSyncProvider = ({
251
247
// Update cache with new data and reset isForced flag
252
248
updateCache ( cacheKey , {
253
249
dbEvents : fetchedData ,
254
- dbLastUpdated : Date . now ( ) ,
255
- isForced : false , // Reset isForced after successful fetch
250
+ dbLastUpdated : Date . now ( )
256
251
} ) ;
252
+
253
+ // Reset the ref immediately (synchronous)
254
+ isForcedRef . current = false ;
257
255
258
256
setData ( fetchedData ) ;
259
257
return fetchedData ;
@@ -592,11 +590,13 @@ export const CalendarSyncProvider = ({
592
590
const isCurrentWeek = includesCurrentWeek ( dates ) ;
593
591
594
592
if ( cacheData ) {
595
- cacheData . isForced = true ;
593
+ isForcedRef . current = true ;
596
594
// For current week, also reset the cache timestamp to force refresh
597
595
if ( isCurrentWeek ) {
598
- cacheData . dbLastUpdated = 0 ;
599
- cacheData . googleLastUpdated = 0 ;
596
+ updateCache ( cacheKey , {
597
+ dbLastUpdated : 0 ,
598
+ googleLastUpdated : 0 ,
599
+ } ) ;
600
600
}
601
601
}
602
602
@@ -694,7 +694,8 @@ export const CalendarSyncProvider = ({
694
694
// If events were deleted, refresh to get updated data
695
695
if ( deletionPerformed ) {
696
696
queryClient . invalidateQueries ( {
697
- queryKey : [ 'calendarEvents' , wsId ] ,
697
+ queryKey : [ 'databaseCalendarEvents' , wsId ] ,
698
+ exact : false ,
698
699
} ) ;
699
700
}
700
701
} catch ( err ) {
@@ -723,17 +724,12 @@ export const CalendarSyncProvider = ({
723
724
const cacheKey = getCacheKey ( dates ) ;
724
725
if ( ! cacheKey ) return null ;
725
726
726
-
727
- // Use updateCache instead of direct mutation
728
- updateCache ( cacheKey , {
729
- isForced : true ,
730
- dbLastUpdated : 0 ,
731
- } ) ;
727
+ isForcedRef . current = true ;
732
728
733
729
queryClient . invalidateQueries ( {
734
730
queryKey : [ 'databaseCalendarEvents' , wsId , getCacheKey ( dates ) ] ,
735
731
} ) ;
736
- } , [ queryClient , wsId , calendarCache , dates , updateCache ] ) ;
732
+ } , [ queryClient , wsId , dates ] ) ;
737
733
738
734
const eventsWithoutAllDays = useMemo ( ( ) => {
739
735
// Process events immediately when they change
0 commit comments