Refactor Alerts
This commit is contained in:
@@ -5,7 +5,7 @@ import SwiftUI
|
||||
public struct ClashModeCard: View {
|
||||
@EnvironmentObject private var commandClient: CommandClient
|
||||
@State private var clashMode: String = ""
|
||||
@State private var alert: Alert?
|
||||
@State private var alert: AlertState?
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -32,7 +32,7 @@ public struct ClashModeCard: View {
|
||||
.onChangeCompat(of: commandClient.clashMode) { newValue in
|
||||
clashMode = newValue
|
||||
}
|
||||
.alertBinding($alert)
|
||||
.alert($alert)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public struct ClashModeCard: View {
|
||||
try LibboxNewStandaloneCommandClient()!.setClashMode(newMode)
|
||||
} catch {
|
||||
await MainActor.run {
|
||||
alert = Alert(error)
|
||||
alert = AlertState(error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public struct ProfileCard: View {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
.alertBinding($viewModel.alert)
|
||||
.alert($viewModel.alert)
|
||||
}
|
||||
|
||||
private var headerView: some View {
|
||||
@@ -254,7 +254,7 @@ extension ProfileCard {
|
||||
@Published var showManageProfiles = false
|
||||
@Published var showQRCode = false
|
||||
@Published var isUpdating = false
|
||||
@Published var alert: Alert?
|
||||
@Published var alert: AlertState?
|
||||
@Published var profileToEdit: Profile?
|
||||
|
||||
func updateProfile(_ profile: Profile, environments: ExtensionEnvironments) async {
|
||||
@@ -264,9 +264,9 @@ extension ProfileCard {
|
||||
try await profile.updateRemoteProfile()
|
||||
environments.profileUpdate.send()
|
||||
} catch {
|
||||
alert = Alert(
|
||||
title: Text("Update Failed"),
|
||||
message: Text(error.localizedDescription)
|
||||
alert = AlertState(
|
||||
title: String(localized: "Update Failed"),
|
||||
message: error.localizedDescription
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@ extension ProfileCard {
|
||||
}
|
||||
}
|
||||
.disabled(viewModel.isUpdating)
|
||||
.alertBinding($viewModel.alert, $viewModel.isLoading)
|
||||
.alert($viewModel.alert, isLoading: $viewModel.isLoading)
|
||||
.onReceive(environments.profileUpdate) { _ in
|
||||
Task {
|
||||
await viewModel.doReload()
|
||||
|
||||
Reference in New Issue
Block a user