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