Compare commits
No commits in common. "ca88c446fbece60411b21745b15ce4c144f2f155" and "7015ccd41f4c35b65747e706c97eab7985857409" have entirely different histories.
ca88c446fb
...
7015ccd41f
@ -6,7 +6,6 @@ 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?
|
||||
@ -15,9 +14,8 @@ struct ContactAddView: View {
|
||||
init(contact: ContactEditInfo, onContactAdded: ((ContactPayload) -> Void)? = nil) {
|
||||
self.contact = contact
|
||||
self.onContactAdded = onContactAdded
|
||||
// let initialName = contact.preferredName
|
||||
self.initialName = contact.preferredName
|
||||
_displayName = State(initialValue: "")
|
||||
let initialName = contact.preferredName
|
||||
_displayName = State(initialValue: initialName)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -25,8 +23,7 @@ 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("\(initialName)", comment: "Display name field placeholder"), text: $displayName)
|
||||
TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
.disabled(isSaving)
|
||||
}
|
||||
}
|
||||
@ -113,7 +110,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
|
||||
@ -141,13 +138,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,6 +40,9 @@ struct ContactEditInfo {
|
||||
}
|
||||
|
||||
var preferredName: String {
|
||||
if let custom = customName?.trimmedNonEmpty {
|
||||
return custom
|
||||
}
|
||||
if let full = fullName?.trimmedNonEmpty {
|
||||
return full
|
||||
}
|
||||
@ -48,14 +51,6 @@ struct ContactEditInfo {
|
||||
}
|
||||
return NSLocalizedString("Неизвестный пользователь", comment: "Message profile fallback title")
|
||||
}
|
||||
|
||||
var loadCustomName: String {
|
||||
if let custom = customName?.trimmedNonEmpty {
|
||||
return custom
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContactEditView: View {
|
||||
@ -65,7 +60,6 @@ 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?
|
||||
@ -81,9 +75,8 @@ struct ContactEditView: View {
|
||||
self.contact = contact
|
||||
self.onContactDeleted = onContactDeleted
|
||||
self.onContactUpdated = onContactUpdated
|
||||
self.initialName = contact.preferredName
|
||||
let initialCustomName = contact.loadCustomName
|
||||
_displayName = State(initialValue: initialCustomName)
|
||||
let initialName = contact.preferredName
|
||||
_displayName = State(initialValue: initialName)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -91,8 +84,7 @@ struct ContactEditView: View {
|
||||
avatarSection
|
||||
|
||||
Section(header: Text(NSLocalizedString("Публичная информация", comment: "Profile info section title"))) {
|
||||
// TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
TextField(NSLocalizedString("\(self.initialName)", comment: "Display name field placeholder"), text: $displayName)
|
||||
TextField(NSLocalizedString("Отображаемое имя", comment: "Display name field placeholder"), text: $displayName)
|
||||
.disabled(isSaving || isDeleting)
|
||||
}
|
||||
|
||||
@ -219,7 +211,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
|
||||
@ -247,13 +239,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