From f6493d1b9042e9f75fb3941f48fbca5b910e8793 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Tue, 7 May 2024 17:45:15 +0400 Subject: [PATCH] swipe on contact list --- .../Chat/Contacts/ContactListNavLink.swift | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift b/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift index 43cc93405d..ac7366a32c 100644 --- a/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift +++ b/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift @@ -11,7 +11,20 @@ import SimpleXChat struct ContactListNavLink: View { @ObservedObject var chat: Chat - + @State private var contactNavLinkSheet: ContactNavLinkActionSheet? = nil + + enum ContactNavLinkActionSheet: Identifiable { + case deleteContactActionSheet + case notifyDeleteContactActionSheet(contactDeleteMode: ContactDeleteMode) + + var id: String { + switch self { + case .deleteContactActionSheet: return "deleteContactActionSheet" + case .notifyDeleteContactActionSheet: return "notifyDeleteContactActionSheet" + } + } + } + var body: some View { // TODO keep bottom bar? switch chat.chatInfo { @@ -37,6 +50,46 @@ struct ContactListNavLink: View { } } } + .swipeActions(edge: .trailing, allowsFullSwipe: true) { + Button { + contactNavLinkSheet = .deleteContactActionSheet + } label: { + Label("Delete", systemImage: "trash") + } + .tint(.red) + } + .actionSheet(item: $contactNavLinkSheet) { sheet in + switch(sheet) { + case .deleteContactActionSheet: + return ActionSheet( + title: Text("Delete contact?"), + buttons: [ + .destructive(Text("Delete contact, keep conversation")) { contactNavLinkSheet = .notifyDeleteContactActionSheet(contactDeleteMode: .entity) }, + .destructive(Text("Delete contact and conversation")) { contactNavLinkSheet = .notifyDeleteContactActionSheet(contactDeleteMode: .full) }, + .cancel() + ] + ) + case let .notifyDeleteContactActionSheet(contactDeleteMode): + if contact.ready && contact.active { + return ActionSheet( + title: Text("Notify contact?\nThis cannot be undone!"), + buttons: [ + .destructive(Text("Delete and notify contact")) { Task { await deleteChatContact(chat, chatDeleteMode: contactDeleteMode.toChatDeleteMode(notify: true)) } }, + .destructive(Text("Delete without notification")) { Task { await deleteChatContact(chat, chatDeleteMode: contactDeleteMode.toChatDeleteMode(notify: false)) } }, + .cancel() + ] + ) + } else { + return ActionSheet( + title: Text("Confirm contact deletion.\nThis cannot be undone!"), + buttons: [ + .destructive(Text("Delete")) { Task { await deleteChatContact(chat, chatDeleteMode: contactDeleteMode.toChatDeleteMode(notify: false)) } }, + .cancel() + ] + ) + } + } + } default: EmptyView() }