diff --git a/PresentationLayer/UIComponents/Screens/Home/HomeViewModel.swift b/PresentationLayer/UIComponents/Screens/Home/HomeViewModel.swift index df105118f..1979ef85d 100644 --- a/PresentationLayer/UIComponents/Screens/Home/HomeViewModel.swift +++ b/PresentationLayer/UIComponents/Screens/Home/HomeViewModel.swift @@ -115,7 +115,6 @@ class HomeViewModel: ObservableObject { do { let forecasts = try await fetchForecasts() self.savedLocationsState = forecasts.isEmpty ? .empty : .forecasts(forecasts) - self.currentLocationState = try await getCurrentLocationState() } catch let error as NetworkErrorResponse { let info = error.uiInfo let obj = info.defaultFailObject(type: .home) { [weak self] in @@ -126,9 +125,15 @@ class HomeViewModel: ObservableObject { self.failObj = obj self.isFailed = true + } catch { + print(error) + } + do { + self.currentLocationState = try await getCurrentLocationState() } catch { print(error) + self.currentLocationState = .empty } self.isLoading = false diff --git a/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsView.swift b/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsView.swift index 6ada87a27..ea3eb42ed 100644 --- a/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsView.swift +++ b/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsView.swift @@ -98,6 +98,7 @@ private struct ContentView: View { .background(Color(colorEnum: .bg)) } + .iPadMaxWidth() } else if devices.isEmpty || !viewModel.isLoggedIn { ZStack { Color(colorEnum: .bg) @@ -111,6 +112,7 @@ private struct ContentView: View { addStationsButton } } + .iPadMaxWidth() } else { weatherStations(devices: devices) .overlay { diff --git a/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsViewModel.swift b/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsViewModel.swift index e93eee11a..dc3e11e3c 100644 --- a/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsViewModel.swift +++ b/PresentationLayer/UIComponents/Screens/WeatherStations/MyStations/MyStationsViewModel.swift @@ -80,6 +80,8 @@ public final class MyStationsViewModel: ObservableObject { mainVM?.$isUserLoggedIn.sink { [weak self] value in self?.isLoggedIn = value + self?.isFailed = false + self?.failObj = nil }.store(in: &cancellableSet) observeFilters() diff --git a/WeatherXMTests/DomainLayer/UseCases/LocationForecastsUseCaseTests.swift b/WeatherXMTests/DomainLayer/UseCases/LocationForecastsUseCaseTests.swift index 93819f022..50293c0e9 100644 --- a/WeatherXMTests/DomainLayer/UseCases/LocationForecastsUseCaseTests.swift +++ b/WeatherXMTests/DomainLayer/UseCases/LocationForecastsUseCaseTests.swift @@ -42,7 +42,7 @@ struct LocationForecastsUseCaseTests { @Test func getCachedForecast() async throws { let cachedforecast = NetworkDeviceForecastResponse(tz: "123", - date: "", + date: Date.now.getFormattedDate(format: .onlyDate), hourly: [], address: "Address") let location = CLLocationCoordinate2D() diff --git a/wxm-ios.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/wxm-ios.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 7f0388f5d..43adc16f8 100644 --- a/wxm-ios.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/wxm-ios.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -312,8 +312,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "2547102afd04fe49f1b286090f13ebce07284980", - "version" : "1.31.1" + "revision" : "97bb244f7a575a419ebc8f3c2d33f2feb9c8f7f2", + "version" : "1.33.1" } }, { diff --git a/wxm-ios/DataLayer/DataLayer/Networking/Interceptors/AuthInterceptor.swift b/wxm-ios/DataLayer/DataLayer/Networking/Interceptors/AuthInterceptor.swift index 0073178b9..3975fe1e2 100644 --- a/wxm-ios/DataLayer/DataLayer/Networking/Interceptors/AuthInterceptor.swift +++ b/wxm-ios/DataLayer/DataLayer/Networking/Interceptors/AuthInterceptor.swift @@ -87,6 +87,8 @@ class AuthInterceptor: @unchecked Sendable, RequestInterceptor { } }.store(in: &cancellableSet) } catch {} - } + } else { + completion(nil) + } } } diff --git a/wxm-ios/DomainLayer/DomainLayer/UseCases/LocationForecastsUseCase.swift b/wxm-ios/DomainLayer/DomainLayer/UseCases/LocationForecastsUseCase.swift index 80ec52ef6..bbdfc83f2 100644 --- a/wxm-ios/DomainLayer/DomainLayer/UseCases/LocationForecastsUseCase.swift +++ b/wxm-ios/DomainLayer/DomainLayer/UseCases/LocationForecastsUseCase.swift @@ -18,7 +18,7 @@ public struct LocationForecastsUseCase: LocationForecastsUseCaseApi { nonisolated(unsafe) private let keychainRepository: KeychainRepository private let savedLocationsUDKey = UserDefaults.GenericKey.savedLocations.rawValue private let forecastsCacheKey = UserDefaults.GenericKey.savedForecasts.rawValue - private let cacheInterval: TimeInterval = 15 * 60 * 60 + private let cacheInterval: TimeInterval = 15 * 60 // 15 mins nonisolated(unsafe) private let notificationsPublisher: NotificationCenter.Publisher = NotificationCenter.default.publisher(for: .savedLocationsUpdated) nonisolated(unsafe) let cache: TimeValidationCache<[NetworkDeviceForecastResponse]> public var locationAuthorization: WXMLocationManager.Status { @@ -49,12 +49,19 @@ public struct LocationForecastsUseCase: LocationForecastsUseCaseApi { public func getForecast(for location: CLLocationCoordinate2D) throws -> AnyPublisher, Never> { if let cachedForecasts: [NetworkDeviceForecastResponse] = cache.getValue(for: location.cacheKey) { + let forecasts = cachedForecasts.filter { forecast in + guard let date = forecast.date.onlyDateStringToDate() else { + return false + } + // Ensure that we return only forecasts later than today + return date.days(from: Date.now) >= 0 + } let response = DataResponse<[NetworkDeviceForecastResponse], NetworkErrorResponse>(request: nil, response: nil, data: nil, metrics: nil, serializationDuration: 0, - result: .success(cachedForecasts)) + result: .success(forecasts)) return Just(response).eraseToAnyPublisher() }