Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion heatguard-iOS/App/HeatGuardApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct HeatGuardApp: App {
@State private var showsTeamFlow = false
@State private var startsAccountRegistration = false
@State private var pendingInvitationToken: String?
@State private var restoredProfile: HGTeamProfile?

var body: some Scene {
WindowGroup {
Expand Down Expand Up @@ -46,6 +47,7 @@ struct HeatGuardApp: App {
}
} else if isAuthenticated {
HomeView(
initialProfile: restoredProfile,
onSessionEnded: handleSessionEnded,
onTeamSelectionRequested: { showsTeamFlow = true }
)
Expand Down Expand Up @@ -77,7 +79,9 @@ struct HeatGuardApp: App {
try? HGAuthTokenStore(account: "app-session-access-token").clear()
UserDefaults.standard.removeObject(forKey: "selected-app-site-id")
do {
isAuthenticated = (try await HGAuthenticationService().restoreSession()) != nil
let session = try await HGAuthenticationService().restoreSession()
restoredProfile = session?.profile
isAuthenticated = session != nil
if isAuthenticated { await routeToSelectedTeamIfNeeded() }
} catch {
isAuthenticated = false
Expand All @@ -87,6 +91,7 @@ struct HeatGuardApp: App {

@MainActor
private func routeAuthenticatedSession() async {
restoredProfile = nil
isAuthenticated = true
await routeToSelectedTeamIfNeeded()
}
Expand Down Expand Up @@ -133,6 +138,7 @@ struct HeatGuardApp: App {
@MainActor
private func handleSessionEnded() {
HGAuthenticationService().endLocalSession()
restoredProfile = nil
isAuthenticated = false
showsTeamFlow = false
}
Expand Down
12 changes: 9 additions & 3 deletions heatguard-iOS/Core/Auth/HGAuthenticationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ struct HGAuthenticationService {
return nil
}

_ = try await currentProfile()
return TeamSession()
let profile = try await currentProfile()
return TeamSession(profile: profile)
}

func currentProfile() async throws -> HGTeamProfile {
Expand Down Expand Up @@ -327,7 +327,13 @@ private struct PasswordChangeResponse: Decodable {

private struct WithdrawalRequest: Encodable { let currentPassword: String; let reason: String? }

struct TeamSession: Equatable {}
struct TeamSession: Equatable {
let profile: HGTeamProfile?

init(profile: HGTeamProfile? = nil) {
self.profile = profile
}
}

struct HGLoginCredentials: Codable {
let email: String
Expand Down
13 changes: 10 additions & 3 deletions heatguard-iOS/Presentation/Features/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ struct HomeView: View {

init(
initialDashboard: HomeDashboard? = nil,
initialProfile: HGTeamProfile? = nil,
onSessionEnded: @escaping () -> Void = {},
onTeamSelectionRequested: @escaping () -> Void = {}
) {
self.onSessionEnded = onSessionEnded
self.onTeamSelectionRequested = onTeamSelectionRequested
self.loadsRemoteData = initialDashboard == nil
_dashboard = State(initialValue: initialDashboard ?? .unavailable)
_teamProfile = State(initialValue: initialProfile)
_checklist = State(initialValue: initialDashboard?.checklist ?? HGChecklistSummary(times: [], checkedCount: nil, totalCount: nil))
_unreadNotificationCount = State(initialValue: initialDashboard?.unreadNotificationCount ?? 0)
}
Expand Down Expand Up @@ -161,10 +163,15 @@ struct HomeView: View {
.navigationDestination(for: HomeFlowRoute.self, destination: destinationView)
.task {
guard loadsRemoteData else { return }
await loadDashboard()
await loadProfile()
await restoreCurrentEmergencyCall()
loadStoredDraft()
async let dashboardLoad: Void = loadDashboard()
async let emergencyLoad: Void = restoreCurrentEmergencyCall()
if teamProfile == nil {
async let profileLoad: Void = loadProfile()
_ = await (dashboardLoad, profileLoad, emergencyLoad)
} else {
_ = await (dashboardLoad, emergencyLoad)
}
}
.alert("홈 데이터를 불러오지 못했습니다.", isPresented: dashboardErrorAlert) {
Button("다시 시도") {
Expand Down
Loading