Avoid reusing category thumbnail images in all recipes preview mosaic

Track which recipe IDs are used as category thumbnails and prefer
different images for the all recipes 2x2 mosaic, falling back to
category thumbnails only when not enough other images are available.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 07:52:18 +01:00
parent 5307b502e9
commit 151e69ff28
2 changed files with 17 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import UIKit
@Published var recipeDetails: [Int: RecipeDetail] = [:]
@Published var timers: [String: RecipeTimer] = [:]
@Published var categoryImages: [String: UIImage] = [:]
@Published var categoryImageRecipeIds: Set<Int> = []
@Published var recentRecipes: [Recipe] = []
@Published var categoryAccessDates: [String: Date] = [:]
@Published var manualCategoryOrder: [String] = []
@@ -320,6 +321,7 @@ import UIKit
for recipe in recipes {
if let image = await getImage(id: recipe.recipe_id, size: .THUMB, fetchMode: .preferLocal) {
self.categoryImages[categoryName] = image
self.categoryImageRecipeIds.insert(recipe.recipe_id)
return
}
}

View File

@@ -72,15 +72,29 @@ struct AllRecipesCategoryCardView: View {
allRecipes.shuffle()
// Filter to recipes that have an image URL, then pick 4
// Prefer recipes not already used as category thumbnails
let categoryImageIds = appState.categoryImageRecipeIds
var candidates: [Recipe] = []
var fallbackCandidates: [Recipe] = []
var seenIds: Set<Int> = []
for recipe in allRecipes {
guard let url = recipe.imageUrl, !url.isEmpty else { continue }
guard !seenIds.contains(recipe.recipe_id) else { continue }
seenIds.insert(recipe.recipe_id)
if categoryImageIds.contains(recipe.recipe_id) {
fallbackCandidates.append(recipe)
} else {
candidates.append(recipe)
}
if candidates.count >= 4 { break }
}
// Fill remaining slots from fallback if needed
if candidates.count < 4 {
for recipe in fallbackCandidates {
candidates.append(recipe)
if candidates.count >= 4 { break }
}
}
var images: [UIImage] = []
for recipe in candidates {