2023-02-18 17:28:16 +00:00
|
|
|
import DesignSystem
|
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
|
2023-09-18 19:03:52 +00:00
|
|
|
@MainActor
|
2023-02-18 17:28:16 +00:00
|
|
|
public struct EditRelationshipNoteView: View {
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
2023-09-18 19:03:52 +00:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(Client.self) private var client
|
2023-02-21 06:23:42 +00:00
|
|
|
|
2023-09-18 05:01:23 +00:00
|
|
|
@State var accountDetailViewModel: AccountDetailViewModel
|
|
|
|
@State private var viewModel = EditRelationshipNoteViewModel()
|
2023-02-21 06:23:42 +00:00
|
|
|
|
2023-02-18 17:28:16 +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)
|
2023-02-18 17:28:16 +00:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 08:48:12 +00:00
|
|
|
#endif
|
2023-02-18 17:28:16 +00:00
|
|
|
}
|
2023-12-19 08:48:12 +00:00
|
|
|
#if !os(visionOS)
|
2023-02-18 17:28:16 +00:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-12-19 08:48:12 +00:00
|
|
|
#endif
|
2023-02-18 17:28:16 +00:00
|
|
|
.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") })
|
2023-02-18 17:28:16 +00:00
|
|
|
.task {
|
|
|
|
viewModel.client = client
|
|
|
|
viewModel.relatedAccountId = accountDetailViewModel.accountId
|
|
|
|
viewModel.note = accountDetailViewModel.relationship?.note ?? ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-21 06:23:42 +00:00
|
|
|
|
2023-02-18 17:28:16 +00:00
|
|
|
@ToolbarContentBuilder
|
|
|
|
private var toolbarContent: some ToolbarContent {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
Button("action.cancel") {
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
}
|
2023-02-21 06:23:42 +00:00
|
|
|
|
2023-02-18 17:28:16 +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()
|
2023-02-18 17:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|