Refactor Alerts

This commit is contained in:
世界
2025-12-01 18:22:06 +08:00
parent 8e764c56eb
commit 4ddfcdb324
40 changed files with 324 additions and 224 deletions
@@ -54,7 +54,7 @@ public struct ConnectionListView: View {
#if os(macOS)
.searchable(text: $viewModel.searchText)
#endif
.alertBinding($viewModel.alert)
.alert($viewModel.alert)
.onAppear {
viewModel.connect()
}
@@ -28,7 +28,7 @@ public class ConnectionListViewModel: BaseViewModel {
private var saveStateFilterTask: Task<Void, Never>?
private var saveSortTask: Task<Void, Never>?
public override init() {
override public init() {
connectionStateFilter = .active
connectionSort = .byDate
super.init()
@@ -70,7 +70,7 @@ public class ConnectionListViewModel: BaseViewModel {
do {
try LibboxNewStandaloneCommandClient()!.closeConnections()
} catch {
alert = Alert(error)
alert = AlertState(error: error)
}
}
@@ -18,7 +18,7 @@ public struct ConnectionView: View {
LibboxFormatDuration(Int64((closedAt.timeIntervalSince1970 - createdAt.timeIntervalSince1970) * 1000))
}
@State private var alert: Alert?
@State private var alert: AlertState?
public var body: some View {
FormNavigationLink {
@@ -86,7 +86,7 @@ public struct ConnectionView: View {
#if !os(tvOS)
.buttonStyle(.borderless)
#endif
.alertBinding($alert)
.alert($alert)
.contextMenu {
if connection.closedAt == nil {
Button("Close", role: .destructive) {
@@ -114,7 +114,7 @@ public struct ConnectionView: View {
try await LibboxNewStandaloneCommandClient()!.closeConnection(connection.id)
} catch {
await MainActor.run {
alert = Alert(error)
alert = AlertState(error: error)
}
}
}