diff --git a/composeApp/src/commonMain/kotlin/com/example/casera/network/APILayer.kt b/composeApp/src/commonMain/kotlin/com/example/casera/network/APILayer.kt index 77a0cfd..420c57c 100644 --- a/composeApp/src/commonMain/kotlin/com/example/casera/network/APILayer.kt +++ b/composeApp/src/commonMain/kotlin/com/example/casera/network/APILayer.kt @@ -393,11 +393,21 @@ object APILayer { } suspend fun getResidence(id: Int, forceRefresh: Boolean = false): ApiResult { - // Check DataManager first - return cached if valid and not forcing refresh - if (!forceRefresh && DataManager.isCacheValid(DataManager.residencesCacheTime)) { - val cached = DataManager.residences.value.find { it.id == id } - if (cached != null) { - return ApiResult.Success(cached) + // Check DataManager caches first - return cached if valid and not forcing refresh + if (!forceRefresh) { + // Check residences list + if (DataManager.isCacheValid(DataManager.residencesCacheTime)) { + val cached = DataManager.residences.value.find { it.id == id } + if (cached != null) { + return ApiResult.Success(cached) + } + } + // Also check myResidences (loaded from home screen) + if (DataManager.isCacheValid(DataManager.myResidencesCacheTime)) { + val cached = DataManager.myResidences.value?.residences?.find { it.id == id } + if (cached != null) { + return ApiResult.Success(cached) + } } } diff --git a/iosApp/iosApp/Task/TaskViewModel.swift b/iosApp/iosApp/Task/TaskViewModel.swift index 1f0aa8b..67a4446 100644 --- a/iosApp/iosApp/Task/TaskViewModel.swift +++ b/iosApp/iosApp/Task/TaskViewModel.swift @@ -300,7 +300,7 @@ class TaskViewModel: ObservableObject { } /// Load tasks - either all tasks or filtered by residence - /// Checks cache first, then fetches if needed. + /// Kotlin's APILayer handles caching - returns cached data if valid without network call. /// - Parameters: /// - residenceId: Optional residence ID to filter by. If nil, loads all tasks. /// - forceRefresh: Whether to bypass cache @@ -309,20 +309,6 @@ class TaskViewModel: ObservableObject { currentResidenceId = residenceId tasksError = nil - - // Check if we have cached data and don't need to refresh - if !forceRefresh { - if let resId = residenceId { - if DataManagerObservable.shared.tasksByResidence[resId] != nil { - // Data already available via observation, no API call needed - return - } - } else if DataManagerObservable.shared.allTasks != nil { - // Data already available via observation, no API call needed - return - } - } - isLoadingTasks = true // Kick off API call - DataManager will be updated, which updates DataManagerObservable,