Create new recipes from CategoryDetailView

This commit is contained in:
Vicnet
2023-10-17 16:21:22 +02:00
parent a025923ba6
commit f55158e99e
3 changed files with 30 additions and 4 deletions

View File

@@ -161,6 +161,22 @@
}
}
},
"Add new recipe" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Neues Rezept"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Nueva Receta"
}
}
}
},
"An unknown error occured." : {
"localizations" : {
"de" : {

View File

@@ -14,6 +14,7 @@ struct CategoryDetailView: View {
@State var categoryName: String
@State var searchText: String = ""
@ObservedObject var viewModel: MainViewModel
@Binding var showEditView: Bool
var body: some View {
ScrollView(showsIndicators: false) {
@@ -33,6 +34,15 @@ struct CategoryDetailView: View {
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Menu {
Button {
print("Add new recipe")
showEditView = true
} label: {
HStack {
Text("Add new recipe")
Image(systemName: "plus.circle.fill")
}
}
Button {
print("Downloading all recipes in category \(categoryName) ...")
downloadRecipes()

View File

@@ -63,14 +63,13 @@ struct MainView: View {
}
ToolbarItem(placement: .topBarTrailing) {
Button {
print("Create recipe")
print("Add new recipe")
showEditView = true
} label: {
HStack {
Image(systemName: "plus.circle.fill")
}
}
}
}
} detail: {
@@ -78,7 +77,8 @@ struct MainView: View {
if let category = selectedCategory {
CategoryDetailView(
categoryName: category.name,
viewModel: viewModel
viewModel: viewModel,
showEditView: $showEditView
)
.id(category.id) // Workaround: This is needed to update the detail view when the selection changes
}