add context menu in contacts list
This commit is contained in:
		
							parent
							
								
									910eef3703
								
							
						
					
					
						commit
						e135556fa6
					
				@ -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" : {
 | 
			
		||||
@ -555,6 +564,9 @@
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "Изменить контакт" : {
 | 
			
		||||
      "comment" : "Contacts context action edit"
 | 
			
		||||
    },
 | 
			
		||||
    "Изображение" : {
 | 
			
		||||
      "comment" : "Image message placeholder"
 | 
			
		||||
    },
 | 
			
		||||
@ -2240,9 +2252,15 @@
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "Удаление контакта \"%1$@\" появится позже." : {
 | 
			
		||||
      "comment" : "Contacts delete placeholder message"
 | 
			
		||||
    },
 | 
			
		||||
    "Удалить из заблокированных?" : {
 | 
			
		||||
      "comment" : "Unblock confirmation title"
 | 
			
		||||
    },
 | 
			
		||||
    "Удалить контакт" : {
 | 
			
		||||
      "comment" : "Contacts context action delete"
 | 
			
		||||
    },
 | 
			
		||||
    "Удалить чат (скоро)" : {
 | 
			
		||||
      "localizations" : {
 | 
			
		||||
        "en" : {
 | 
			
		||||
 | 
			
		||||
@ -462,7 +462,7 @@ struct ChatsTab: View {
 | 
			
		||||
            }
 | 
			
		||||
            .hidden()
 | 
			
		||||
        )
 | 
			
		||||
        .listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
 | 
			
		||||
        .listRowInsets(EdgeInsets(top: 4, leading: 16, bottom: 4, trailing: 16))
 | 
			
		||||
//        .listRowSeparator(.hidden)
 | 
			
		||||
        .onAppear {
 | 
			
		||||
            guard !isSearching else { return }
 | 
			
		||||
 | 
			
		||||
@ -20,15 +20,40 @@ struct ContactsTab: View {
 | 
			
		||||
            } else {
 | 
			
		||||
                ForEach(contacts) { contact in
 | 
			
		||||
                    Button {
 | 
			
		||||
                        activeAlert = .info(
 | 
			
		||||
                            title: NSLocalizedString("Скоро", comment: "Contacts placeholder title"),
 | 
			
		||||
                            message: String(format: NSLocalizedString("Просмотр \"%1$@\" появится позже.", comment: "Contacts placeholder message"), contact.displayName)
 | 
			
		||||
                        )
 | 
			
		||||
                        showContactPlaceholder(for: contact)
 | 
			
		||||
                    } label: {
 | 
			
		||||
                        ContactRow(contact: contact)
 | 
			
		||||
                            .contentShape(Rectangle())
 | 
			
		||||
                    }
 | 
			
		||||
                    .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))
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@ -128,6 +153,23 @@ struct ContactsTab: View {
 | 
			
		||||
 | 
			
		||||
        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 {
 | 
			
		||||
@ -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
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user