Updated RecipeView
This commit is contained in:
@@ -18,16 +18,12 @@ struct Category: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Category: Identifiable, Hashable {
|
||||
var id: String { name }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// MARK: - Login flow
|
||||
|
||||
struct LoginV2Request: Codable {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// ObservableRecipeDetail.swift
|
||||
// Nextcloud Cookbook iOS Client
|
||||
//
|
||||
// Created by Vincent Meilinger on 01.03.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
class ObservableRecipeDetail: ObservableObject {
|
||||
var id: String
|
||||
@Published var name: String
|
||||
@Published var keywords: [String]
|
||||
@Published var imageUrl: String
|
||||
@Published var prepTime: DurationComponents
|
||||
@Published var cookTime: DurationComponents
|
||||
@Published var totalTime: DurationComponents
|
||||
@Published var description: String
|
||||
@Published var url: String
|
||||
@Published var recipeYield: Int
|
||||
@Published var recipeCategory: String
|
||||
@Published var tool: [ReorderableItem<String>]
|
||||
@Published var recipeIngredient: [ReorderableItem<String>]
|
||||
@Published var recipeInstructions: [ReorderableItem<String>]
|
||||
@Published var nutrition: [String:String]
|
||||
|
||||
init() {
|
||||
id = ""
|
||||
name = String(localized: "New Recipe")
|
||||
keywords = []
|
||||
imageUrl = ""
|
||||
prepTime = DurationComponents()
|
||||
cookTime = DurationComponents()
|
||||
totalTime = DurationComponents()
|
||||
description = ""
|
||||
url = ""
|
||||
recipeYield = 0
|
||||
recipeCategory = ""
|
||||
tool = []
|
||||
recipeIngredient = []
|
||||
recipeInstructions = []
|
||||
nutrition = [:]
|
||||
}
|
||||
|
||||
init(_ recipeDetail: RecipeDetail) {
|
||||
id = recipeDetail.id
|
||||
name = recipeDetail.name
|
||||
keywords = recipeDetail.keywords.components(separatedBy: ",")
|
||||
imageUrl = recipeDetail.imageUrl
|
||||
prepTime = DurationComponents.fromPTString(recipeDetail.prepTime ?? "")
|
||||
cookTime = DurationComponents.fromPTString(recipeDetail.cookTime ?? "")
|
||||
totalTime = DurationComponents.fromPTString(recipeDetail.totalTime ?? "")
|
||||
description = recipeDetail.description
|
||||
url = recipeDetail.url
|
||||
recipeYield = recipeDetail.recipeYield
|
||||
recipeCategory = recipeDetail.recipeCategory
|
||||
tool = ReorderableItem.list(items: recipeDetail.tool)
|
||||
recipeIngredient = ReorderableItem.list(items: recipeDetail.recipeIngredient)
|
||||
recipeInstructions = ReorderableItem.list(items: recipeDetail.recipeInstructions)
|
||||
nutrition = recipeDetail.nutrition
|
||||
}
|
||||
|
||||
func toRecipeDetail() -> RecipeDetail {
|
||||
return RecipeDetail(
|
||||
name: self.name,
|
||||
keywords: self.keywords.joined(separator: ","),
|
||||
dateCreated: "",
|
||||
dateModified: "",
|
||||
imageUrl: self.imageUrl,
|
||||
id: self.id,
|
||||
prepTime: self.prepTime.toPTString(),
|
||||
cookTime: self.cookTime.toPTString(),
|
||||
totalTime: self.totalTime.toPTString(),
|
||||
description: self.description,
|
||||
url: self.url,
|
||||
recipeYield: self.recipeYield,
|
||||
recipeCategory: self.recipeCategory,
|
||||
tool: ReorderableItem.items(self.tool),
|
||||
recipeIngredient: ReorderableItem.items(self.recipeIngredient),
|
||||
recipeInstructions: ReorderableItem.items(self.recipeInstructions),
|
||||
nutrition: self.nutrition
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -146,7 +146,8 @@ struct RecipeKeyword: Codable {
|
||||
|
||||
|
||||
enum Nutrition: CaseIterable {
|
||||
case calories,
|
||||
case servingSize,
|
||||
calories,
|
||||
carbohydrateContent,
|
||||
cholesterolContent,
|
||||
fatContent,
|
||||
@@ -158,35 +159,39 @@ enum Nutrition: CaseIterable {
|
||||
sodiumContent,
|
||||
sugarContent
|
||||
|
||||
var localizedDescription: LocalizedStringKey {
|
||||
var localizedDescription: String {
|
||||
switch self {
|
||||
case .servingSize:
|
||||
return NSLocalizedString("Serving size", comment: "Serving size")
|
||||
case .calories:
|
||||
"Calories"
|
||||
return NSLocalizedString("Calories", comment: "Calories")
|
||||
case .carbohydrateContent:
|
||||
"Carbohydrate content"
|
||||
return NSLocalizedString("Carbohydrate content", comment: "Carbohydrate content")
|
||||
case .cholesterolContent:
|
||||
"Cholesterol content"
|
||||
return NSLocalizedString("Cholesterol content", comment: "Cholesterol content")
|
||||
case .fatContent:
|
||||
"Fat content"
|
||||
return NSLocalizedString("Fat content", comment: "Fat content")
|
||||
case .saturatedFatContent:
|
||||
"Saturated fat content"
|
||||
return NSLocalizedString("Saturated fat content", comment: "Saturated fat content")
|
||||
case .unsaturatedFatContent:
|
||||
"Unsaturated fat content"
|
||||
return NSLocalizedString("Unsaturated fat content", comment: "Unsaturated fat content")
|
||||
case .transFatContent:
|
||||
"Trans fat content"
|
||||
return NSLocalizedString("Trans fat content", comment: "Trans fat content")
|
||||
case .fiberContent:
|
||||
"Fiber content"
|
||||
return NSLocalizedString("Fiber content", comment: "Fiber content")
|
||||
case .proteinContent:
|
||||
"Protein content"
|
||||
return NSLocalizedString("Protein content", comment: "Protein content")
|
||||
case .sodiumContent:
|
||||
"Sodium content"
|
||||
return NSLocalizedString("Sodium content", comment: "Sodium content")
|
||||
case .sugarContent:
|
||||
"Sugar content"
|
||||
return NSLocalizedString("Sugar content", comment: "Sugar content")
|
||||
}
|
||||
}
|
||||
|
||||
var dictKey: String {
|
||||
switch self {
|
||||
case .servingSize:
|
||||
"servingSize"
|
||||
case .calories:
|
||||
"calories"
|
||||
case .carbohydrateContent:
|
||||
|
||||
Reference in New Issue
Block a user