feat(delete): implement delete button

This commit is contained in:
2025-12-01 15:39:10 +01:00
parent d4f2d928b6
commit 987d327613

View File

@@ -79,8 +79,7 @@ struct VocabularyGridView: View {
Divider() Divider()
// Entries list // Entries list
ScrollView { List {
LazyVStack(spacing: 12) {
ForEach(filteredEntries, id: \.id) { entry in ForEach(filteredEntries, id: \.id) { entry in
VocabularyEntryRow( VocabularyEntryRow(
entry: entry, entry: entry,
@@ -91,12 +90,19 @@ struct VocabularyGridView: View {
showDefinition(for: entry, fieldType: fieldType) showDefinition(for: entry, fieldType: fieldType)
} }
) )
.listRowInsets(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
.listRowSeparator(.hidden)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) {
deleteEntry(entry)
} label: {
Label("Delete", systemImage: "trash")
} }
.onDelete(perform: deleteEntries)
} }
.padding()
} }
} }
.listStyle(.plain)
}
.navigationTitle("Wörterbuch") .navigationTitle("Wörterbuch")
.toolbar { .toolbar {
ToolbarItem(placement: .navigationBarTrailing) { ToolbarItem(placement: .navigationBarTrailing) {
@@ -184,9 +190,9 @@ struct VocabularyGridView: View {
} }
} }
private func deleteEntries(offsets: IndexSet) { private func deleteEntry(_ entry: VocabularyEntry) {
withAnimation { withAnimation {
offsets.map { filteredEntries[$0] }.forEach(viewContext.delete) viewContext.delete(entry)
saveContext() saveContext()
} }
} }