Code cleanup
This commit is contained in:
@@ -28,7 +28,7 @@ struct CategoryDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationDestination(for: Recipe.self) { recipe in
|
.navigationDestination(for: Recipe.self) { recipe in
|
||||||
RecipeDetailView(viewModel: viewModel, recipe: recipe)//.id(recipe.recipe_id)
|
RecipeDetailView(viewModel: viewModel, recipe: recipe)
|
||||||
}
|
}
|
||||||
.navigationTitle(categoryName == "*" ? "Other" : categoryName)
|
.navigationTitle(categoryName == "*" ? "Other" : categoryName)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|||||||
@@ -100,13 +100,10 @@ struct MainView: View {
|
|||||||
self.selectedCategory = cat
|
self.selectedCategory = cat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.refreshable {
|
.refreshable {
|
||||||
await viewModel.loadCategoryList(needsUpdate: true)
|
await viewModel.loadCategoryList(needsUpdate: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: SET DEFAULT CATEGORY
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,14 +100,14 @@ struct RecipeDetailView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct RecipeDurationSection: View {
|
fileprivate struct RecipeDurationSection: View {
|
||||||
@State var recipeDetail: RecipeDetail
|
@State var recipeDetail: RecipeDetail
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
if let prepTime = recipeDetail.prepTime {
|
if let prepTime = recipeDetail.prepTime {
|
||||||
VStack {
|
VStack {
|
||||||
SecondaryLabel(text: String(localized: "Prep time"))
|
SecondaryLabel(text: LocalizedStringKey("Preparation"))
|
||||||
Text(DateFormatter.formatDate(duration: prepTime))
|
Text(DateFormatter.formatDate(duration: prepTime))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}.padding()
|
}.padding()
|
||||||
@@ -115,7 +115,7 @@ struct RecipeDurationSection: View {
|
|||||||
|
|
||||||
if let cookTime = recipeDetail.cookTime {
|
if let cookTime = recipeDetail.cookTime {
|
||||||
VStack {
|
VStack {
|
||||||
SecondaryLabel(text: String(localized: "Cook time"))
|
SecondaryLabel(text: LocalizedStringKey("Cooking"))
|
||||||
Text(DateFormatter.formatDate(duration: cookTime))
|
Text(DateFormatter.formatDate(duration: cookTime))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}.padding()
|
}.padding()
|
||||||
@@ -123,7 +123,7 @@ struct RecipeDurationSection: View {
|
|||||||
|
|
||||||
if let totalTime = recipeDetail.totalTime {
|
if let totalTime = recipeDetail.totalTime {
|
||||||
VStack {
|
VStack {
|
||||||
SecondaryLabel(text: String(localized: "Total time"))
|
SecondaryLabel(text: LocalizedStringKey("Total time"))
|
||||||
Text(DateFormatter.formatDate(duration: totalTime))
|
Text(DateFormatter.formatDate(duration: totalTime))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}.padding()
|
}.padding()
|
||||||
@@ -133,18 +133,19 @@ struct RecipeDurationSection: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct RecipeIngredientSection: View {
|
|
||||||
|
fileprivate struct RecipeIngredientSection: View {
|
||||||
@State var recipeDetail: RecipeDetail
|
@State var recipeDetail: RecipeDetail
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Divider()
|
Divider()
|
||||||
HStack {
|
HStack {
|
||||||
if recipeDetail.recipeYield == 0 {
|
if recipeDetail.recipeYield == 0 {
|
||||||
SecondaryLabel(text: String(localized: "Ingredients"))
|
SecondaryLabel(text: LocalizedStringKey("Ingredients"))
|
||||||
} else if recipeDetail.recipeYield == 1 {
|
} else if recipeDetail.recipeYield == 1 {
|
||||||
SecondaryLabel(text: String(localized: "Ingredients per serving"))
|
SecondaryLabel(text: LocalizedStringKey("Ingredients per serving"))
|
||||||
} else {
|
} else {
|
||||||
SecondaryLabel(text: String(localized: "Ingredients for \(recipeDetail.recipeYield) servings"))
|
SecondaryLabel(text: LocalizedStringKey("Ingredients for \(recipeDetail.recipeYield) servings"))
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
@@ -156,7 +157,9 @@ struct RecipeIngredientSection: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IngredientListItem: View {
|
|
||||||
|
|
||||||
|
fileprivate struct IngredientListItem: View {
|
||||||
@State var ingredient: String
|
@State var ingredient: String
|
||||||
@State var isSelected: Bool = false
|
@State var isSelected: Bool = false
|
||||||
|
|
||||||
@@ -180,13 +183,15 @@ struct IngredientListItem: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RecipeToolSection: View {
|
|
||||||
|
|
||||||
|
fileprivate struct RecipeToolSection: View {
|
||||||
@State var recipeDetail: RecipeDetail
|
@State var recipeDetail: RecipeDetail
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Divider()
|
Divider()
|
||||||
HStack {
|
HStack {
|
||||||
SecondaryLabel(text: String(localized: "Tools"))
|
SecondaryLabel(text: LocalizedStringKey("Tools"))
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
ForEach(recipeDetail.tool, id: \.self) { tool in
|
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
|
@State var recipeDetail: RecipeDetail
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Divider()
|
Divider()
|
||||||
HStack {
|
HStack {
|
||||||
SecondaryLabel(text: String(localized: "Instructions"))
|
SecondaryLabel(text: LocalizedStringKey("Instructions"))
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
ForEach(0..<recipeDetail.recipeInstructions.count) { ix in
|
ForEach(0..<recipeDetail.recipeInstructions.count) { ix in
|
||||||
@@ -222,9 +229,8 @@ struct RecipeInstructionSection: View {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fileprivate struct SecondaryLabel: View {
|
||||||
struct SecondaryLabel: View {
|
let text: LocalizedStringKey
|
||||||
let text: String
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text(text)
|
Text(text)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
|||||||
@@ -10,50 +10,6 @@ import SwiftUI
|
|||||||
import PhotosUI
|
import PhotosUI
|
||||||
|
|
||||||
|
|
||||||
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."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct RecipeEditView: View {
|
struct RecipeEditView: View {
|
||||||
@ObservedObject var viewModel: MainViewModel
|
@ObservedObject var viewModel: MainViewModel
|
||||||
@@ -332,7 +288,7 @@ struct RecipeEditView: View {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct EditableListSection: View {
|
fileprivate struct EditableListSection: View {
|
||||||
@State var title: LocalizedStringKey
|
@State var title: LocalizedStringKey
|
||||||
@Binding var items: [String]
|
@Binding var items: [String]
|
||||||
|
|
||||||
@@ -377,7 +333,7 @@ struct EditableListSection: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct DurationPicker: View {
|
fileprivate struct DurationPicker: View {
|
||||||
@State var title: LocalizedStringKey
|
@State var title: LocalizedStringKey
|
||||||
@ObservedObject var duration: Duration
|
@ObservedObject var duration: Duration
|
||||||
|
|
||||||
@@ -401,7 +357,9 @@ struct DurationPicker: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Duration: ObservableObject {
|
|
||||||
|
|
||||||
|
fileprivate class Duration: ObservableObject {
|
||||||
@Published var minuteComponent: String = "00" {
|
@Published var minuteComponent: String = "00" {
|
||||||
didSet {
|
didSet {
|
||||||
if minuteComponent.count > 2 {
|
if minuteComponent.count > 2 {
|
||||||
@@ -449,3 +407,49 @@ class Duration: ObservableObject {
|
|||||||
return "PT\(hourComponent)H\(minuteComponent)M00S"
|
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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user