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,23 +79,29 @@ struct VocabularyGridView: View {
Divider()
// Entries list
ScrollView {
LazyVStack(spacing: 12) {
ForEach(filteredEntries, id: \.id) { entry in
VocabularyEntryRow(
entry: entry,
onSelectField: { fieldType in
openFieldEditor(for: entry, fieldType: fieldType)
},
onLongPress: { fieldType in
showDefinition(for: entry, fieldType: fieldType)
}
)
List {
ForEach(filteredEntries, id: \.id) { entry in
VocabularyEntryRow(
entry: entry,
onSelectField: { fieldType in
openFieldEditor(for: entry, fieldType: fieldType)
},
onLongPress: { fieldType in
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")
.toolbar {
@@ -184,9 +190,9 @@ struct VocabularyGridView: View {
}
}
private func deleteEntries(offsets: IndexSet) {
private func deleteEntry(_ entry: VocabularyEntry) {
withAnimation {
offsets.map { filteredEntries[$0] }.forEach(viewContext.delete)
viewContext.delete(entry)
saveContext()
}
}