Updated RecipeView

This commit is contained in:
VincentMeilinger
2024-03-01 14:17:24 +01:00
parent d3e0366ce6
commit 744ea76a34
41 changed files with 588 additions and 383 deletions

View File

@@ -50,12 +50,14 @@ struct RecipeTabView: View {
.navigationDestination(isPresented: $viewModel.presentSettingsView) {
SettingsView()
}
.navigationDestination(isPresented: $viewModel.presentEditView) {
RecipeView(viewModel: RecipeView.ViewModel())
}
} detail: {
NavigationStack {
if let category = viewModel.selectedCategory {
RecipeListView(
categoryName: category.name,
viewModel: mainViewModel,
showEditView: $viewModel.presentEditView
)
.id(category.id) // Workaround: This is needed to update the detail view when the selection changes
@@ -63,7 +65,8 @@ struct RecipeTabView: View {
}
}
.tint(.nextcloudBlue)
.sheet(isPresented: $viewModel.presentEditView) {
/*.sheet(isPresented: $viewModel.presentEditView) {
RecipeEditView(
viewModel:
RecipeEditViewModel(
@@ -72,7 +75,7 @@ struct RecipeTabView: View {
),
isPresented: $viewModel.presentEditView
)
}
}*/
.task {
viewModel.serverConnection = await mainViewModel.checkServerConnection()
}

View File

@@ -11,7 +11,7 @@ import SimilaritySearchKit
struct SearchTabView: View {
@EnvironmentObject var viewModel: SearchTabView.ViewModel
@EnvironmentObject var mainViewModel: AppState
@EnvironmentObject var appState: AppState
var body: some View {
NavigationStack {
@@ -27,7 +27,7 @@ struct SearchTabView: View {
LazyVStack {
ForEach(viewModel.recipesFiltered(), id: \.recipe_id) { recipe in
NavigationLink(value: recipe) {
RecipeCardView(viewModel: mainViewModel, recipe: recipe)
RecipeCardView(recipe: recipe)
.shadow(radius: 2)
}
.buttonStyle(.plain)
@@ -35,7 +35,7 @@ struct SearchTabView: View {
}
}
.navigationDestination(for: Recipe.self) { recipe in
RecipeView(appState: mainViewModel, viewModel: RecipeView.ViewModel(recipe: recipe))
RecipeView(viewModel: RecipeView.ViewModel(recipe: recipe))
}
.searchable(text: $viewModel.searchText, prompt: "Search recipes/keywords")
}
@@ -43,11 +43,11 @@ struct SearchTabView: View {
}
.task {
if viewModel.allRecipes.isEmpty {
viewModel.allRecipes = await mainViewModel.getRecipes()
viewModel.allRecipes = await appState.getRecipes()
}
}
.refreshable {
viewModel.allRecipes = await mainViewModel.getRecipes()
viewModel.allRecipes = await appState.getRecipes()
}
}