fix in add contact and update contact inforamation
This commit is contained in:
parent
7015ccd41f
commit
bc73eb37be
@ -6,6 +6,7 @@ struct ContactAddView: View {
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
private let contactsService = ContactsService()
|
||||
private let initialName: String
|
||||
|
||||
@State private var displayName: String
|
||||
@State private var activeAlert: ContactAddAlert?
|
||||
@ -14,8 +15,9 @@ struct ContactAddView: View {
|
||||
init(contact: ContactEditInfo, onContactAdded: ((ContactPayload) -> Void)? = nil) {
|
||||
self.contact = contact
|
||||
self.onContactAdded = onContactAdded
|
||||
let initialName = contact.preferredName
|
||||
_displayName = State(initialValue: initialName)
|
||||
// let initialName = contact.preferredName
|
||||
self.initialName = contact.preferredName
|
||||
_displayName = State(initialValue: "")
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -23,7 +25,8 @@ struct ContactAddView: View {
|
||||
avatarSection
|
||||
|
||||
Section(header: Text(NSLocalizedString("Публичная информация", comment: "Contact add public info section title"))) {
|
||||
TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
// TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
TextField(NSLocalizedString("\(initialName)", comment: "Display name field placeholder"), text: $displayName)
|
||||
.disabled(isSaving)
|
||||
}
|
||||
}
|
||||
@ -110,7 +113,7 @@ struct ContactAddView: View {
|
||||
|
||||
private var hasChanges: Bool {
|
||||
let trimmed = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return false }
|
||||
// guard !trimmed.isEmpty else { return false }
|
||||
|
||||
if let existing = contact.customName?.trimmedNonEmpty {
|
||||
return trimmed != existing
|
||||
@ -138,13 +141,13 @@ struct ContactAddView: View {
|
||||
}
|
||||
|
||||
let trimmedName = displayName.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
guard !trimmedName.isEmpty else {
|
||||
activeAlert = ContactAddAlert(
|
||||
title: NSLocalizedString("Ошибка", comment: "Common error title"),
|
||||
message: NSLocalizedString("Имя не может быть пустым.", comment: "Contact add empty name error")
|
||||
)
|
||||
return
|
||||
}
|
||||
// guard !trimmedName.isEmpty else {
|
||||
// activeAlert = ContactAddAlert(
|
||||
// title: NSLocalizedString("Ошибка", comment: "Common error title"),
|
||||
// message: NSLocalizedString("Имя не может быть пустым.", comment: "Contact add empty name error")
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
|
||||
isSaving = true
|
||||
let customName = trimmedName
|
||||
|
||||
@ -40,9 +40,6 @@ struct ContactEditInfo {
|
||||
}
|
||||
|
||||
var preferredName: String {
|
||||
if let custom = customName?.trimmedNonEmpty {
|
||||
return custom
|
||||
}
|
||||
if let full = fullName?.trimmedNonEmpty {
|
||||
return full
|
||||
}
|
||||
@ -51,6 +48,14 @@ struct ContactEditInfo {
|
||||
}
|
||||
return NSLocalizedString("Неизвестный пользователь", comment: "Message profile fallback title")
|
||||
}
|
||||
|
||||
var loadCustomName: String {
|
||||
if let custom = customName?.trimmedNonEmpty {
|
||||
return custom
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContactEditView: View {
|
||||
@ -60,6 +65,7 @@ struct ContactEditView: View {
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
private let contactsService = ContactsService()
|
||||
private let initialName: String
|
||||
|
||||
@State private var displayName: String
|
||||
@State private var activeAlert: ContactEditAlert?
|
||||
@ -72,11 +78,12 @@ struct ContactEditView: View {
|
||||
onContactDeleted: (() -> Void)? = nil,
|
||||
onContactUpdated: ((String) -> Void)? = nil
|
||||
) {
|
||||
self.contact = contact
|
||||
self.contact = contact //TODO
|
||||
self.onContactDeleted = onContactDeleted
|
||||
self.onContactUpdated = onContactUpdated
|
||||
let initialName = contact.preferredName
|
||||
_displayName = State(initialValue: initialName)
|
||||
self.initialName = contact.preferredName
|
||||
let initialCustomName = contact.loadCustomName
|
||||
_displayName = State(initialValue: initialCustomName)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -84,7 +91,8 @@ struct ContactEditView: View {
|
||||
avatarSection
|
||||
|
||||
Section(header: Text(NSLocalizedString("Публичная информация", comment: "Profile info section title"))) {
|
||||
TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
// TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
TextField(NSLocalizedString("\(self.initialName)", comment: "Display name field placeholder"), text: $displayName)
|
||||
.disabled(isSaving || isDeleting)
|
||||
}
|
||||
|
||||
@ -211,7 +219,7 @@ struct ContactEditView: View {
|
||||
|
||||
private var hasChanges: Bool {
|
||||
let trimmed = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return false }
|
||||
// guard !trimmed.isEmpty else { return false }
|
||||
|
||||
if let existing = contact.customName?.trimmedNonEmpty {
|
||||
return trimmed != existing
|
||||
@ -239,13 +247,13 @@ struct ContactEditView: View {
|
||||
}
|
||||
|
||||
let trimmed = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else {
|
||||
activeAlert = ContactEditAlert(
|
||||
title: NSLocalizedString("Ошибка", comment: "Common error title"),
|
||||
message: NSLocalizedString("Имя не может быть пустым.", comment: "Contact edit empty name error")
|
||||
)
|
||||
return
|
||||
}
|
||||
// guard !trimmed.isEmpty else {
|
||||
// activeAlert = ContactEditAlert(
|
||||
// title: NSLocalizedString("Ошибка", comment: "Common error title"),
|
||||
// message: NSLocalizedString("Имя не может быть пустым.", comment: "Contact edit empty name error")
|
||||
// )
|
||||
// return
|
||||
// }
|
||||
|
||||
if trimmed.count > 32 {
|
||||
activeAlert = ContactEditAlert(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user