add context menu in contacts list

This commit is contained in:
cheykrym 2025-10-23 23:46:19 +03:00
parent 910eef3703
commit e135556fa6
3 changed files with 91 additions and 5 deletions

View File

@ -214,6 +214,9 @@
} }
} }
}, },
"Блокировка контакта \"%1$@\" появится позже." : {
"comment" : "Contacts block placeholder message"
},
"В чате пока нет сообщений." : { "В чате пока нет сообщений." : {
}, },
@ -413,6 +416,9 @@
}, },
"Заблокированные пользователи" : { "Заблокированные пользователи" : {
},
"Заблокировать контакт" : {
"comment" : "Contacts context action block"
}, },
"Заблокируйте аккаунт, чтобы скрыть его сообщения и взаимодействия" : { "Заблокируйте аккаунт, чтобы скрыть его сообщения и взаимодействия" : {
@ -544,6 +550,9 @@
}, },
"Избранные сообщения" : { "Избранные сообщения" : {
},
"Изменение контакта \"%1$@\" появится позже." : {
"comment" : "Contacts edit placeholder message"
}, },
"Изменение пароля" : { "Изменение пароля" : {
"localizations" : { "localizations" : {
@ -555,6 +564,9 @@
} }
} }
}, },
"Изменить контакт" : {
"comment" : "Contacts context action edit"
},
"Изображение" : { "Изображение" : {
"comment" : "Image message placeholder" "comment" : "Image message placeholder"
}, },
@ -2240,9 +2252,15 @@
} }
} }
}, },
"Удаление контакта \"%1$@\" появится позже." : {
"comment" : "Contacts delete placeholder message"
},
"Удалить из заблокированных?" : { "Удалить из заблокированных?" : {
"comment" : "Unblock confirmation title" "comment" : "Unblock confirmation title"
}, },
"Удалить контакт" : {
"comment" : "Contacts context action delete"
},
"Удалить чат (скоро)" : { "Удалить чат (скоро)" : {
"localizations" : { "localizations" : {
"en" : { "en" : {

View File

@ -462,7 +462,7 @@ struct ChatsTab: View {
} }
.hidden() .hidden()
) )
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16)) .listRowInsets(EdgeInsets(top: 4, leading: 16, bottom: 4, trailing: 16))
// .listRowSeparator(.hidden) // .listRowSeparator(.hidden)
.onAppear { .onAppear {
guard !isSearching else { return } guard !isSearching else { return }

View File

@ -20,15 +20,40 @@ struct ContactsTab: View {
} else { } else {
ForEach(contacts) { contact in ForEach(contacts) { contact in
Button { Button {
activeAlert = .info( showContactPlaceholder(for: contact)
title: NSLocalizedString("Скоро", comment: "Contacts placeholder title"),
message: String(format: NSLocalizedString("Просмотр \"%1$@\" появится позже.", comment: "Contacts placeholder message"), contact.displayName)
)
} label: { } label: {
ContactRow(contact: contact) ContactRow(contact: contact)
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.contextMenu {
Button {
handleContactAction(.edit, for: contact)
} label: {
Label(
NSLocalizedString("Изменить контакт", comment: "Contacts context action edit"),
systemImage: "square.and.pencil"
)
}
Button {
handleContactAction(.block, for: contact)
} label: {
Label(
NSLocalizedString("Заблокировать контакт", comment: "Contacts context action block"),
systemImage: "hand.raised.fill"
)
}
Button(role: .destructive) {
handleContactAction(.delete, for: contact)
} label: {
Label(
NSLocalizedString("Удалить контакт", comment: "Contacts context action delete"),
systemImage: "trash"
)
}
}
.listRowInsets(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12)) .listRowInsets(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12))
} }
} }
@ -128,6 +153,23 @@ struct ContactsTab: View {
isLoading = false isLoading = false
} }
private func showContactPlaceholder(for contact: Contact) {
activeAlert = .info(
title: NSLocalizedString("Скоро", comment: "Contacts placeholder title"),
message: String(
format: NSLocalizedString("Просмотр \"%1$@\" появится позже.", comment: "Contacts placeholder message"),
contact.displayName
)
)
}
private func handleContactAction(_ action: ContactAction, for contact: Contact) {
activeAlert = .info(
title: NSLocalizedString("Скоро", comment: "Contacts placeholder title"),
message: action.placeholderMessage(for: contact)
)
}
} }
private struct ContactRow: View { private struct ContactRow: View {
@ -254,3 +296,29 @@ private enum ContactsAlert: Identifiable {
} }
} }
} }
private enum ContactAction {
case edit
case block
case delete
func placeholderMessage(for contact: Contact) -> String {
switch self {
case .edit:
return String(
format: NSLocalizedString("Изменение контакта \"%1$@\" появится позже.", comment: "Contacts edit placeholder message"),
contact.displayName
)
case .block:
return String(
format: NSLocalizedString("Блокировка контакта \"%1$@\" появится позже.", comment: "Contacts block placeholder message"),
contact.displayName
)
case .delete:
return String(
format: NSLocalizedString("Удаление контакта \"%1$@\" появится позже.", comment: "Contacts delete placeholder message"),
contact.displayName
)
}
}
}