experiment(PodcastPlayerView): add swipe-to-delete in PodcastLibraryView, stops player if active
This commit is contained in:
@@ -589,7 +589,8 @@ struct PodcastLibraryView: View {
|
||||
description: Text("Podcasts you generate will appear here.")
|
||||
)
|
||||
} else {
|
||||
List(entries) { entry in
|
||||
List {
|
||||
ForEach(entries) { entry in
|
||||
HStack(spacing: 12) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(entry.title ?? entry.articleUrl)
|
||||
@@ -613,6 +614,17 @@ struct PodcastLibraryView: View {
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
.padding(.vertical, 6)
|
||||
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
||||
Button(role: .destructive) {
|
||||
deleteEntry(entry)
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onDelete { indexSet in
|
||||
indexSet.forEach { deleteEntry(entries[$0]) }
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
@@ -627,4 +639,10 @@ struct PodcastLibraryView: View {
|
||||
}
|
||||
.onAppear { entries = PodcastIndex.all() }
|
||||
}
|
||||
|
||||
private func deleteEntry(_ entry: PodcastEntry) {
|
||||
PodcastIndex.remove(articleUrl: entry.articleUrl)
|
||||
entries.removeAll { $0.articleUrl == entry.articleUrl }
|
||||
if vm.currentArticleUrl == entry.articleUrl { vm.stop() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user