Fixed disappearing images when updating recipes

This commit is contained in:
VincentMeilinger
2025-05-26 23:56:52 +02:00
parent d7272026bb
commit 31dd6c6926
3 changed files with 12 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ class ObservableRecipeDetail: ObservableObject {
var id: String var id: String
@Published var name: String @Published var name: String
@Published var keywords: [String] @Published var keywords: [String]
@Published var image: String
@Published var imageUrl: String @Published var imageUrl: String
@Published var prepTime: DurationComponents @Published var prepTime: DurationComponents
@Published var cookTime: DurationComponents @Published var cookTime: DurationComponents
@@ -35,6 +36,7 @@ class ObservableRecipeDetail: ObservableObject {
id = "" id = ""
name = String(localized: "New Recipe") name = String(localized: "New Recipe")
keywords = [] keywords = []
image = ""
imageUrl = "" imageUrl = ""
prepTime = DurationComponents() prepTime = DurationComponents()
cookTime = DurationComponents() cookTime = DurationComponents()
@@ -55,6 +57,7 @@ class ObservableRecipeDetail: ObservableObject {
id = recipeDetail.id id = recipeDetail.id
name = recipeDetail.name name = recipeDetail.name
keywords = recipeDetail.keywords.isEmpty ? [] : recipeDetail.keywords.components(separatedBy: ",") keywords = recipeDetail.keywords.isEmpty ? [] : recipeDetail.keywords.components(separatedBy: ",")
image = recipeDetail.image ?? ""
imageUrl = recipeDetail.imageUrl ?? "" imageUrl = recipeDetail.imageUrl ?? ""
prepTime = DurationComponents.fromPTString(recipeDetail.prepTime ?? "") prepTime = DurationComponents.fromPTString(recipeDetail.prepTime ?? "")
cookTime = DurationComponents.fromPTString(recipeDetail.cookTime ?? "") cookTime = DurationComponents.fromPTString(recipeDetail.cookTime ?? "")
@@ -77,6 +80,7 @@ class ObservableRecipeDetail: ObservableObject {
keywords: self.keywords.joined(separator: ","), keywords: self.keywords.joined(separator: ","),
dateCreated: "", dateCreated: "",
dateModified: "", dateModified: "",
image: self.image,
imageUrl: self.imageUrl, imageUrl: self.imageUrl,
id: self.id, id: self.id,
prepTime: self.prepTime.toPTString(), prepTime: self.prepTime.toPTString(),

View File

@@ -38,6 +38,7 @@ struct RecipeDetail: Codable {
var dateCreated: String? var dateCreated: String?
var dateModified: String? var dateModified: String?
var imageUrl: String? var imageUrl: String?
var image: String?
var id: String var id: String
var prepTime: String? var prepTime: String?
var cookTime: String? var cookTime: String?
@@ -51,11 +52,12 @@ struct RecipeDetail: Codable {
var recipeInstructions: [String] var recipeInstructions: [String]
var nutrition: [String:String] var nutrition: [String:String]
init(name: String, keywords: String, dateCreated: String, dateModified: String, imageUrl: String, id: String, prepTime: String? = nil, cookTime: String? = nil, totalTime: String? = nil, description: String, url: String, recipeYield: Int, recipeCategory: String, tool: [String], recipeIngredient: [String], recipeInstructions: [String], nutrition: [String:String]) { init(name: String, keywords: String, dateCreated: String, dateModified: String, image: String, imageUrl: String, id: String, prepTime: String? = nil, cookTime: String? = nil, totalTime: String? = nil, description: String, url: String, recipeYield: Int, recipeCategory: String, tool: [String], recipeIngredient: [String], recipeInstructions: [String], nutrition: [String:String]) {
self.name = name self.name = name
self.keywords = keywords self.keywords = keywords
self.dateCreated = dateCreated self.dateCreated = dateCreated
self.dateModified = dateModified self.dateModified = dateModified
self.image = image
self.imageUrl = imageUrl self.imageUrl = imageUrl
self.id = id self.id = id
self.prepTime = prepTime self.prepTime = prepTime
@@ -76,6 +78,7 @@ struct RecipeDetail: Codable {
keywords = "" keywords = ""
dateCreated = "" dateCreated = ""
dateModified = "" dateModified = ""
image = ""
imageUrl = "" imageUrl = ""
id = "" id = ""
prepTime = "" prepTime = ""
@@ -93,7 +96,7 @@ struct RecipeDetail: Codable {
// Custom decoder to handle value type ambiguity // Custom decoder to handle value type ambiguity
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case name, keywords, dateCreated, dateModified, imageUrl, id, prepTime, cookTime, totalTime, description, url, recipeYield, recipeCategory, tool, recipeIngredient, recipeInstructions, nutrition case name, keywords, dateCreated, dateModified, image, imageUrl, id, prepTime, cookTime, totalTime, description, url, recipeYield, recipeCategory, tool, recipeIngredient, recipeInstructions, nutrition
} }
init(from decoder: Decoder) throws { init(from decoder: Decoder) throws {
@@ -102,6 +105,7 @@ struct RecipeDetail: Codable {
keywords = try container.decode(String.self, forKey: .keywords) keywords = try container.decode(String.self, forKey: .keywords)
dateCreated = try container.decodeIfPresent(String.self, forKey: .dateCreated) dateCreated = try container.decodeIfPresent(String.self, forKey: .dateCreated)
dateModified = try container.decodeIfPresent(String.self, forKey: .dateModified) dateModified = try container.decodeIfPresent(String.self, forKey: .dateModified)
image = try container.decodeIfPresent(String.self, forKey: .image)
imageUrl = try container.decodeIfPresent(String.self, forKey: .imageUrl) imageUrl = try container.decodeIfPresent(String.self, forKey: .imageUrl)
id = try container.decode(String.self, forKey: .id) id = try container.decode(String.self, forKey: .id)
prepTime = try container.decodeIfPresent(String.self, forKey: .prepTime) prepTime = try container.decodeIfPresent(String.self, forKey: .prepTime)
@@ -116,6 +120,7 @@ struct RecipeDetail: Codable {
recipeInstructions = try container.decode([String].self, forKey: .recipeInstructions) recipeInstructions = try container.decode([String].self, forKey: .recipeInstructions)
nutrition = try container.decode(Dictionary<String, JSONAny>.self, forKey: .nutrition).mapValues { String(describing: $0.value) } nutrition = try container.decode(Dictionary<String, JSONAny>.self, forKey: .nutrition).mapValues { String(describing: $0.value) }
} }
} }
@@ -127,6 +132,7 @@ extension RecipeDetail {
keywords: "", keywords: "",
dateCreated: "", dateCreated: "",
dateModified: "", dateModified: "",
image: "",
imageUrl: "", imageUrl: "",
id: "", id: "",
prepTime: "", prepTime: "",