Fixed a crash due to a race condition in RecipeListView

This commit is contained in:
VincentMeilinger
2024-03-10 12:50:42 +01:00
parent 2c749754f4
commit 5d82cdf0c2
4 changed files with 32 additions and 11 deletions

View File

@@ -48,7 +48,6 @@ struct RecipeCardView: View {
}
.background(Color.backgroundHighlight)
.clipShape(RoundedRectangle(cornerRadius: 17))
.padding(.horizontal)
.task {
recipeThumb = await appState.getImage(
id: recipe.recipe_id,
@@ -67,5 +66,6 @@ struct RecipeCardView: View {
fetchMode: UserSettings.shared.storeThumb ? .preferServer : .onlyServer
)
}
.frame(height: 80)
}
}

View File

@@ -17,10 +17,9 @@ struct RecipeListView: View {
@State var searchText: String = ""
@Binding var showEditView: Bool
@State var selectedRecipe: Recipe? = nil
@State var presentRecipeView: Bool = false
var body: some View {
ScrollView(showsIndicators: false) {
/*ScrollView(showsIndicators: false) {
LazyVStack {
ForEach(recipesFiltered(), id: \.recipe_id) { recipe in
NavigationLink(value: recipe) {
@@ -31,17 +30,35 @@ struct RecipeListView: View {
.buttonStyle(.plain)
.onTapGesture {
selectedRecipe = recipe
presentRecipeView = true
//presentRecipeView = true
}
}
}
}*/
List(recipesFiltered(), id: \.recipe_id) { recipe in
RecipeCardView(recipe: recipe)
.shadow(radius: 2)
.background(
NavigationLink(value: recipe) {
EmptyView()
}
.buttonStyle(.plain)
.opacity(0)
)
.frame(height: 85)
.listRowInsets(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
.listRowSeparatorTint(.clear)
}
.listStyle(.plain)
.searchable(text: $searchText, prompt: "Search recipes/keywords")
.navigationTitle(categoryName == "*" ? String(localized: "Other") : categoryName)
.navigationDestination(for: Recipe.self) { recipe in
RecipeView(viewModel: RecipeView.ViewModel(recipe: recipe))
.environmentObject(appState)
.environmentObject(groceryList)
}
.navigationTitle(categoryName == "*" ? String(localized: "Other") : categoryName)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
@@ -52,7 +69,6 @@ struct RecipeListView: View {
}
}
}
.searchable(text: $searchText, prompt: "Search recipes/keywords")
.task {
await appState.getCategory(
named: categoryName,

View File

@@ -13,13 +13,12 @@ struct RecipeTabView: View {
@EnvironmentObject var appState: AppState
@EnvironmentObject var groceryList: GroceryList
@EnvironmentObject var viewModel: RecipeTabView.ViewModel
@EnvironmentObject var mainViewModel: AppState
var body: some View {
NavigationSplitView {
List(selection: $viewModel.selectedCategory) {
// Categories
ForEach(mainViewModel.categories) { category in
ForEach(appState.categories) { category in
if category.recipe_count != 0 {
NavigationLink(value: category) {
HStack(alignment: .center) {
@@ -72,11 +71,17 @@ struct RecipeTabView: View {
}
.tint(.nextcloudBlue)
.task {
viewModel.serverConnection = await mainViewModel.checkServerConnection()
let connection = await appState.checkServerConnection()
DispatchQueue.main.async {
viewModel.serverConnection = connection
}
}
.refreshable {
viewModel.serverConnection = await mainViewModel.checkServerConnection()
await mainViewModel.getCategories()
let connection = await appState.checkServerConnection()
DispatchQueue.main.async {
viewModel.serverConnection = connection
}
await appState.getCategories()
}
}