From bc73eb37bede4afe414dcef0b3975a804c3e5c05 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Fri, 12 Dec 2025 04:02:18 +0300 Subject: [PATCH] fix in add contact and update contact inforamation --- yobble/Views/Contacts/ContactAddView.swift | 25 ++++++++------ yobble/Views/Contacts/ContactEditView.swift | 38 +++++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/yobble/Views/Contacts/ContactAddView.swift b/yobble/Views/Contacts/ContactAddView.swift index 9ced035..7fb12b4 100644 --- a/yobble/Views/Contacts/ContactAddView.swift +++ b/yobble/Views/Contacts/ContactAddView.swift @@ -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 diff --git a/yobble/Views/Contacts/ContactEditView.swift b/yobble/Views/Contacts/ContactEditView.swift index e3ac816..9ca6c4e 100644 --- a/yobble/Views/Contacts/ContactEditView.swift +++ b/yobble/Views/Contacts/ContactEditView.swift @@ -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(