diff --git a/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift b/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift index 31127f3..c594935 100644 --- a/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift +++ b/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift @@ -28,7 +28,7 @@ struct CategoryDetailView: View { } } .navigationDestination(for: Recipe.self) { recipe in - RecipeDetailView(viewModel: viewModel, recipe: recipe)//.id(recipe.recipe_id) + RecipeDetailView(viewModel: viewModel, recipe: recipe) } .navigationTitle(categoryName == "*" ? "Other" : categoryName) .toolbar { diff --git a/Nextcloud Cookbook iOS Client/Views/MainView.swift b/Nextcloud Cookbook iOS Client/Views/MainView.swift index 8719975..a2d12d5 100644 --- a/Nextcloud Cookbook iOS Client/Views/MainView.swift +++ b/Nextcloud Cookbook iOS Client/Views/MainView.swift @@ -100,13 +100,10 @@ struct MainView: View { self.selectedCategory = cat } } - } .refreshable { await viewModel.loadCategoryList(needsUpdate: true) } - - // TODO: SET DEFAULT CATEGORY } } diff --git a/Nextcloud Cookbook iOS Client/Views/RecipeDetailView.swift b/Nextcloud Cookbook iOS Client/Views/RecipeDetailView.swift index 9cedebe..169cee1 100644 --- a/Nextcloud Cookbook iOS Client/Views/RecipeDetailView.swift +++ b/Nextcloud Cookbook iOS Client/Views/RecipeDetailView.swift @@ -100,14 +100,14 @@ struct RecipeDetailView: View { } -struct RecipeDurationSection: View { +fileprivate struct RecipeDurationSection: View { @State var recipeDetail: RecipeDetail var body: some View { HStack(alignment: .center) { if let prepTime = recipeDetail.prepTime { VStack { - SecondaryLabel(text: String(localized: "Prep time")) + SecondaryLabel(text: LocalizedStringKey("Preparation")) Text(DateFormatter.formatDate(duration: prepTime)) .lineLimit(1) }.padding() @@ -115,7 +115,7 @@ struct RecipeDurationSection: View { if let cookTime = recipeDetail.cookTime { VStack { - SecondaryLabel(text: String(localized: "Cook time")) + SecondaryLabel(text: LocalizedStringKey("Cooking")) Text(DateFormatter.formatDate(duration: cookTime)) .lineLimit(1) }.padding() @@ -123,7 +123,7 @@ struct RecipeDurationSection: View { if let totalTime = recipeDetail.totalTime { VStack { - SecondaryLabel(text: String(localized: "Total time")) + SecondaryLabel(text: LocalizedStringKey("Total time")) Text(DateFormatter.formatDate(duration: totalTime)) .lineLimit(1) }.padding() @@ -133,18 +133,19 @@ struct RecipeDurationSection: View { } -struct RecipeIngredientSection: View { + +fileprivate struct RecipeIngredientSection: View { @State var recipeDetail: RecipeDetail var body: some View { VStack(alignment: .leading) { Divider() HStack { if recipeDetail.recipeYield == 0 { - SecondaryLabel(text: String(localized: "Ingredients")) + SecondaryLabel(text: LocalizedStringKey("Ingredients")) } else if recipeDetail.recipeYield == 1 { - SecondaryLabel(text: String(localized: "Ingredients per serving")) + SecondaryLabel(text: LocalizedStringKey("Ingredients per serving")) } else { - SecondaryLabel(text: String(localized: "Ingredients for \(recipeDetail.recipeYield) servings")) + SecondaryLabel(text: LocalizedStringKey("Ingredients for \(recipeDetail.recipeYield) servings")) } Spacer() } @@ -156,7 +157,9 @@ struct RecipeIngredientSection: View { } } -struct IngredientListItem: View { + + +fileprivate struct IngredientListItem: View { @State var ingredient: String @State var isSelected: Bool = false @@ -180,13 +183,15 @@ struct IngredientListItem: View { } } -struct RecipeToolSection: View { + + +fileprivate struct RecipeToolSection: View { @State var recipeDetail: RecipeDetail var body: some View { VStack(alignment: .leading) { Divider() HStack { - SecondaryLabel(text: String(localized: "Tools")) + SecondaryLabel(text: LocalizedStringKey("Tools")) Spacer() } ForEach(recipeDetail.tool, id: \.self) { tool in @@ -201,13 +206,15 @@ struct RecipeToolSection: View { } } -struct RecipeInstructionSection: View { + + +fileprivate struct RecipeInstructionSection: View { @State var recipeDetail: RecipeDetail var body: some View { VStack(alignment: .leading) { Divider() HStack { - SecondaryLabel(text: String(localized: "Instructions")) + SecondaryLabel(text: LocalizedStringKey("Instructions")) Spacer() } ForEach(0.. 2 { @@ -449,3 +407,49 @@ class Duration: ObservableObject { return "PT\(hourComponent)H\(minuteComponent)M00S" } } + + + +fileprivate enum ErrorMessages: Error { + + case NO_TITLE, + DUPLICATE, + UPLOAD_ERROR, + CONFIRM_DELETE, + GENERIC, + CUSTOM(title: LocalizedStringKey, description: LocalizedStringKey) + + var localizedDescription: LocalizedStringKey { + switch self { + case .NO_TITLE: + return "Please enter a recipe name." + case .DUPLICATE: + return "A recipe with that name already exists." + case .UPLOAD_ERROR: + return "Unable to upload your recipe. Please check your internet connection." + case .CONFIRM_DELETE: + return "This action is not reversible!" + case .CUSTOM(title: _, description: let description): + return description + default: + return "An unknown error occured." + } + } + + var localizedTitle: LocalizedStringKey { + switch self { + case .NO_TITLE: + return "Missing recipe name." + case .DUPLICATE: + return "Duplicate recipe." + case .UPLOAD_ERROR: + return "Network error." + case .CONFIRM_DELETE: + return "Delete recipe?" + case .CUSTOM(title: let title, description: _): + return title + default: + return "Error." + } + } +}