From 81522aef22e45e80a1131f2d2dae1ba29f264711 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 1 Mar 2022 14:30:12 -0800 Subject: [PATCH] show context menu on button tap --- .../Components/FeedCardNavigationLink.swift | 3 ++- .../App/Views/Home/HomeFeedViewIOS.swift | 9 +++++++ .../Sources/Views/HomeFeedCardView.swift | 27 ++++++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index a7a3276aa..7557374c1 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -35,6 +35,7 @@ struct GridCardNavigationLink: View { let item: FeedItem let searchQuery: String + let actionHandler: (GridCardAction) -> Void @Binding var selectedLinkItem: FeedItem? @@ -47,7 +48,7 @@ struct GridCardNavigationLink: View { tag: item, selection: $selectedLinkItem ) { - GridCard(item: item) + GridCard(item: item, actionHandler: actionHandler) } .buttonStyle(FlatLinkStyle()) .onAppear { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 926e55535..241aca58f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -248,6 +248,15 @@ import Views let link = GridCardNavigationLink( item: item, searchQuery: searchQuery, + actionHandler: { action in + switch action { + case .toggleArchiveStatus: + viewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: !item.isArchived) + case .delete: + itemToRemove = item + confirmationShown = true + } + }, selectedLinkItem: $selectedLinkItem, viewModel: viewModel ) diff --git a/apple/OmnivoreKit/Sources/Views/HomeFeedCardView.swift b/apple/OmnivoreKit/Sources/Views/HomeFeedCardView.swift index 0d559f443..5fb4e8675 100644 --- a/apple/OmnivoreKit/Sources/Views/HomeFeedCardView.swift +++ b/apple/OmnivoreKit/Sources/Views/HomeFeedCardView.swift @@ -50,11 +50,18 @@ public struct FeedCard: View { } } +public enum GridCardAction { + case toggleArchiveStatus + case delete +} + public struct GridCard: View { let item: FeedItem + let actionHandler: (GridCardAction) -> Void - public init(item: FeedItem) { + public init(item: FeedItem, actionHandler: @escaping (GridCardAction) -> Void) { self.item = item + self.actionHandler = actionHandler } public var body: some View { @@ -77,8 +84,22 @@ public struct GridCard: View { .foregroundColor(.appGrayTextContrast) .lineLimit(1) Spacer() - Button( - action: { print("grid button tapped") }, + Menu( + content: { + Button( + action: { actionHandler(.toggleArchiveStatus) }, + label: { + Label( + item.isArchived ? "Unarchive" : "Archive", + systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" + ) + } + ) + Button( + action: { actionHandler(.delete) }, + label: { Label("Delete Link", systemImage: "trash") } + ) + }, label: { Image.profile } ) }