Account URL is now fetched async (#2769)

This commit is contained in:
Mauro
2024-04-30 19:08:32 +02:00
committed by GitHub
parent f688d2eda4
commit 18dc9cd20f
16 changed files with 47 additions and 70 deletions
@@ -27,13 +27,12 @@ enum SettingsScreenCoordinatorAction {
case logout
case secureBackup
case userDetails
case accountProfile
case analytics
case appLock
case bugReport
case about
case blockedUsers
case accountSessions
case manageAccount(url: URL)
case notifications
case advancedSettings
case developerOptions
@@ -64,8 +63,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.dismiss)
case .userDetails:
actionsSubject.send(.userDetails)
case .accountProfile:
actionsSubject.send(.accountProfile)
case let .manageAccount(url):
actionsSubject.send(.manageAccount(url: url))
case .analytics:
actionsSubject.send(.analytics)
case .appLock:
@@ -78,8 +77,6 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.blockedUsers)
case .secureBackup:
actionsSubject.send(.secureBackup)
case .accountSessionsList:
actionsSubject.send(.accountSessions)
case .notifications:
actionsSubject.send(.notifications)
case .advancedSettings:
@@ -17,17 +17,16 @@
import Foundation
import UIKit
enum SettingsScreenViewModelAction {
enum SettingsScreenViewModelAction: Equatable {
case close
case userDetails
case accountProfile
case manageAccount(url: URL)
case analytics
case appLock
case reportBug
case about
case blockedUsers
case secureBackup
case accountSessionsList
case notifications
case advancedSettings
case developerOptions
@@ -57,14 +56,13 @@ struct SettingsScreenViewState: BindableState {
enum SettingsScreenViewAction {
case close
case userDetails
case accountProfile
case analytics
case appLock
case reportBug
case about
case blockedUsers
case secureBackup
case accountSessionsList
case manageAccount(url: URL)
case notifications
case developerOptions
case advancedSettings
@@ -29,8 +29,6 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
init(userSession: UserSessionProtocol, appSettings: AppSettings) {
super.init(initialViewState: .init(deviceID: userSession.deviceID,
userID: userSession.userID,
accountProfileURL: userSession.clientProxy.accountURL(action: .profile),
accountSessionsListURL: userSession.clientProxy.accountURL(action: .sessionsList),
showDeveloperOptions: appSettings.isDevelopmentBuild),
imageProvider: userSession.mediaProvider)
@@ -81,6 +79,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
Task {
await userSession.clientProxy.loadUserAvatarURL()
await userSession.clientProxy.loadUserDisplayName()
await state.accountProfileURL = userSession.clientProxy.accountURL(action: .profile)
await state.accountSessionsListURL = userSession.clientProxy.accountURL(action: .sessionsList)
}
}
@@ -90,8 +90,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
actionsSubject.send(.close)
case .userDetails:
actionsSubject.send(.userDetails)
case .accountProfile:
actionsSubject.send(.accountProfile)
case let .manageAccount(url):
actionsSubject.send(.manageAccount(url: url))
case .analytics:
actionsSubject.send(.analytics)
case .appLock:
@@ -108,8 +108,6 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
actionsSubject.send(.secureBackup)
case .notifications:
actionsSubject.send(.notifications)
case .accountSessionsList:
actionsSubject.send(.accountSessionsList)
case .advancedSettings:
actionsSubject.send(.advancedSettings)
case .developerOptions:
@@ -29,9 +29,7 @@ struct SettingsScreen: View {
mainSection
if context.viewState.accountSessionsListURL != nil {
manageSessionsSection
}
manageSessionsSection
advancedOptionsSection
@@ -95,11 +93,11 @@ struct SettingsScreen: View {
private var mainSection: some View {
Section {
if context.viewState.accountProfileURL != nil {
if let url = context.viewState.accountProfileURL {
ListRow(label: .default(title: L10n.actionManageAccount,
icon: \.userProfile),
kind: .button {
context.send(viewAction: .accountProfile)
context.send(viewAction: .manageAccount(url: url))
})
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.account)
}
@@ -150,13 +148,16 @@ struct SettingsScreen: View {
}
}
@ViewBuilder
private var manageSessionsSection: some View {
Section {
ListRow(label: .default(title: L10n.actionManageDevices,
icon: \.devices),
kind: .button {
context.send(viewAction: .accountSessionsList)
})
if let url = context.viewState.accountSessionsListURL {
Section {
ListRow(label: .default(title: L10n.actionManageDevices,
icon: \.devices),
kind: .button {
context.send(viewAction: .manageAccount(url: url))
})
}
}
}
@@ -252,6 +253,7 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
NavigationStack {
SettingsScreen(context: viewModel.context)
.snapshot(delay: 1.0)
}
}
}