mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
extract contextMenuView action into function
This commit is contained in:
parent
81522aef22
commit
0289cacad9
2 changed files with 31 additions and 53 deletions
|
|
@ -241,6 +241,16 @@ import Views
|
|||
|
||||
private let columns = Array(repeating: GridItem(.flexible(), spacing: 20), count: 2)
|
||||
|
||||
func contextMenuActionHandler(item: FeedItem, action: GridCardAction) {
|
||||
switch action {
|
||||
case .toggleArchiveStatus:
|
||||
viewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: !item.isArchived)
|
||||
case .delete:
|
||||
itemToRemove = item
|
||||
confirmationShown = true
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns, spacing: 20) {
|
||||
|
|
@ -248,27 +258,10 @@ 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
|
||||
}
|
||||
},
|
||||
actionHandler: { contextMenuActionHandler(item: item, action: $0) },
|
||||
selectedLinkItem: $selectedLinkItem,
|
||||
viewModel: viewModel
|
||||
)
|
||||
.contextMenu {
|
||||
FeedItemContextMenuView(
|
||||
item: item,
|
||||
selectedLinkItem: $selectedLinkItem,
|
||||
snoozePresented: $snoozePresented,
|
||||
itemToSnooze: $itemToSnooze,
|
||||
viewModel: viewModel
|
||||
)
|
||||
}
|
||||
if #available(iOS 15.0, *) {
|
||||
link
|
||||
.alert("Are you sure?", isPresented: $confirmationShown) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,24 @@ public struct GridCard: View {
|
|||
self.actionHandler = actionHandler
|
||||
}
|
||||
|
||||
var contextMenuView: some View {
|
||||
Group {
|
||||
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") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
// Progress Bar
|
||||
|
|
@ -84,24 +102,7 @@ public struct GridCard: View {
|
|||
.foregroundColor(.appGrayTextContrast)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
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 }
|
||||
)
|
||||
Menu(content: { contextMenuView }, label: { Image.profile })
|
||||
}
|
||||
|
||||
HStack {
|
||||
|
|
@ -164,23 +165,7 @@ public struct GridCard: View {
|
|||
}
|
||||
.background(Color(.secondarySystemGroupedBackground))
|
||||
.cornerRadius(6)
|
||||
}
|
||||
}
|
||||
|
||||
struct TextChipdep: View {
|
||||
let text: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
Capsule()
|
||||
.fill(color.opacity(0.3))
|
||||
.border(color.opacity(0.7), width: 3)
|
||||
.overlay(
|
||||
Text(text)
|
||||
.font(.appFootnote)
|
||||
.foregroundColor(color)
|
||||
.padding()
|
||||
)
|
||||
.contextMenu { contextMenuView }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue