From b6cb628cb46e3e9f7a1bdb9e67f945d551252d16 Mon Sep 17 00:00:00 2001 From: itsnotrin Date: Wed, 11 Dec 2024 10:17:26 +0000 Subject: [PATCH] Make it refresh token if it says it's expired. Add highlight to current day in timetable view. --- BetterClasscharts/MainTabView.swift | 4 ++++ BetterClasscharts/StudentClient.swift | 29 +++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/BetterClasscharts/MainTabView.swift b/BetterClasscharts/MainTabView.swift index ac9c9f3..47d56cf 100644 --- a/BetterClasscharts/MainTabView.swift +++ b/BetterClasscharts/MainTabView.swift @@ -236,6 +236,10 @@ struct TimetableView: View { Group { if isCurrentDay(day) { Theme.surfaceColor(for: appTheme, colorScheme: colorScheme) + .overlay( + RoundedRectangle(cornerRadius: 12) + .stroke(Color.purple, lineWidth: 3) + ) } else { selectedDay == day ? Theme.accentColor(for: appTheme) : Theme.surfaceColor(for: appTheme, colorScheme: colorScheme) } diff --git a/BetterClasscharts/StudentClient.swift b/BetterClasscharts/StudentClient.swift index a90ddf3..384fce6 100644 --- a/BetterClasscharts/StudentClient.swift +++ b/BetterClasscharts/StudentClient.swift @@ -263,22 +263,25 @@ class StudentClient { request: @escaping (@escaping (Result) -> Void) -> Void ) { request { result in - if case .failure(let error) = result, - let networkError = error as? NetworkError, - networkError == .sessionExpired { - // Session expired, refresh and retry once - checkAndRefreshSession { refreshResult in - switch refreshResult { - case .success: - // Token refreshed, retry the original request - request(completion) - case .failure(let refreshError): - // Token refresh failed, return the error - completion(.failure(refreshError)) + if case .failure(let error) = result { + if let networkError = error as? NetworkError, + (networkError == .sessionExpired || networkError == .missingUserData) { + // Session expired or missing user data, refresh and retry once + checkAndRefreshSession { refreshResult in + switch refreshResult { + case .success: + // Token refreshed, retry the original request + request(completion) + case .failure(let refreshError): + // Token refresh failed, return the error + completion(.failure(refreshError)) + } } + } else { + // Not a session expiration or second attempt, return the result + completion(result) } } else { - // Not a session expiration or second attempt, return the result completion(result) } }