IceCubesApp/Packages/Account/Sources/Account/Edit/EditRelationshipNoteView.swift

72 lines
2 KiB
Swift
Raw Normal View History

import DesignSystem
import Network
import SwiftUI
2023-09-18 19:03:52 +00:00
@MainActor
public struct EditRelationshipNoteView: View {
@Environment(\.dismiss) private var dismiss
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
@Environment(Client.self) private var client
2023-02-21 06:23:42 +00:00
@State var accountDetailViewModel: AccountDetailViewModel
@State private var viewModel = EditRelationshipNoteViewModel()
2023-02-21 06:23:42 +00:00
public var body: some View {
NavigationStack {
Form {
Section("account.relation.note.label") {
TextField("account.relation.note.edit.placeholder", text: $viewModel.note, axis: .vertical)
.frame(minHeight: 150, maxHeight: 150, alignment: .top)
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
.navigationTitle("account.relation.note.edit")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
toolbarContent
}
.alert("account.relation.note.edit.error.save.title",
isPresented: $viewModel.saveError,
actions: {
2023-02-21 06:23:42 +00:00
Button("alert.button.ok", action: {})
}, message: { Text("account.relation.note.edit.error.save.message") })
.task {
viewModel.client = client
viewModel.relatedAccountId = accountDetailViewModel.accountId
viewModel.note = accountDetailViewModel.relationship?.note ?? ""
}
}
}
2023-02-21 06:23:42 +00:00
@ToolbarContentBuilder
private var toolbarContent: some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button("action.cancel") {
dismiss()
}
}
2023-02-21 06:23:42 +00:00
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Task {
await viewModel.save()
await accountDetailViewModel.fetchAccount()
dismiss()
}
} label: {
if viewModel.isSaving {
ProgressView()
} else {
2023-02-22 21:12:10 +00:00
Text("action.save").bold()
}
}
}
}
}