This commit is contained in:
VincentMeilinger
2024-01-24 20:54:50 +01:00
parent 48d3da1964
commit fbcdfbff12
3 changed files with 35 additions and 15 deletions

View File

@@ -180,12 +180,14 @@ class GroceryList: ObservableObject {
groceryDict.removeValue(forKey: recipeId)
}
save()
objectWillChange.send()
}
func deleteGroceryRecipe(_ recipeId: String) {
print("Deleting grocery recipe with id \(recipeId)")
groceryDict.removeValue(forKey: recipeId)
save()
objectWillChange.send()
}
func deleteAll() {
@@ -200,6 +202,18 @@ class GroceryList: ObservableObject {
save()
}
func containsItem(at recipeId: String, item: String) -> Bool {
guard let recipe = groceryDict[recipeId] else { return false }
if recipe.items.contains(where: { $0.name == item }) {
return true
}
return false
}
func containsRecipe(_ recipeId: String) -> Bool {
return groceryDict[recipeId] != nil
}
func save() {
Task {
await dataStore.save(data: groceryDict, toPath: "grocery_list.data")