Skip to content

Commit

Permalink
Added recipe detail view, some ui adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
cabmatthew committed Dec 12, 2024
1 parent 0261f7a commit 7a751db
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 25 deletions.
Binary file not shown.
21 changes: 21 additions & 0 deletions SwiftFood/Assets.xcassets/food.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "food.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file added SwiftFood/Assets.xcassets/food.imageset/food.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions SwiftFood/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct ContentView: View {
VStack {
Image("kitchen")
.resizable()
.scaledToFit() // Maintains aspect ratio
.frame(width: 300) // Limits the width to 300
.scaledToFit()
.frame(width: 300)

Text("My Little Kitchen.")
.font(.largeTitle)
Expand Down
5 changes: 3 additions & 2 deletions SwiftFood/Views/MyIngredientList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ struct MyIngredientList: View {

var body: some View {
VStack {
Text("My Ingredients")
.font(.headline)
Text("Ingredients")
.font(.title2)
.fontWeight(.bold)

// Text input fields
// Uses accessibility identifiers, easy to access during testing
Expand Down
6 changes: 4 additions & 2 deletions SwiftFood/Views/RecipeCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ struct RecipeCreate: View {

var body: some View {
VStack {
Text("My Ingredients")
.font(.headline)
Text("New Recipe")
.font(.title2)
.fontWeight(.bold)

// Text input fields
// Uses accessibility identifiers, easy to access during testing
Expand Down Expand Up @@ -80,6 +81,7 @@ struct RecipeCreate: View {
.accessibilityIdentifier("AddRecipeButton")
.buttonStyle(.borderedProminent)
}
.padding()
}

func addRecipe() {
Expand Down
33 changes: 33 additions & 0 deletions SwiftFood/Views/RecipeDetail.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// RecipeDetail.swift
// SwiftFood
//
// Created by Matthew Caballero on 12/11/24.
//

import SwiftUI

struct RecipeDetail: View {
var recipe: Recipe

var body: some View {
ScrollView {
Image("food")
.resizable()
.scaledToFit()
.frame(width: 250)
VStack {
Text(recipe.title)
.font(.largeTitle)
.padding()
Text("Time required: \(String(format: "%.1f", recipe.time_required)) hours")
Text("Serving count: \(recipe.servings_amount) servings")

Text("Instructions:")
.font(.title)
.padding()
Text(recipe.instructions)
}
}
}
}
45 changes: 26 additions & 19 deletions SwiftFood/Views/RecipeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,42 @@ struct RecipeList: View {

var body: some View {
VStack {
Text("My Recipes")
.font(.headline)
Text("Recipes")
.font(.title2)
.fontWeight(.bold)

List {
// For each recipe in recipes context
ForEach(myRecipes) { recipe in
HStack {
VStack(alignment: .leading) {
Text(recipe.title)
.font(.headline)
// Formatting to show the decimal correctly
Text("\(String(format: "%.1f", recipe.time_required)) hours")
Text("\(recipe.servings_amount) servings")
}
Spacer()
NavigationLink {
RecipeDetail(recipe: recipe)
} label: {

// Delete Button
Button(action: {
deleteItem(recipe)
}) {
Image(systemName: "trash")
.foregroundColor(.red)
HStack {
VStack(alignment: .leading) {
Text(recipe.title)
.font(.headline)
// Formatting to show the decimal correctly
Text("\(String(format: "%.1f", recipe.time_required)) hours")
Text("\(recipe.servings_amount) servings")
}
Spacer()

// Delete Button
Button(action: {
deleteItem(recipe)
}) {
Image(systemName: "trash")
.foregroundColor(.red)
}
.buttonStyle(.borderless)
}
.buttonStyle(.borderless)
}
}

}
.cornerRadius(20)
NavigationLink("Create new recipe!") {
NavigationLink("Create new recipe") {
RecipeCreate()
}
.accessibilityIdentifier("ToRecipeCreate")
Expand Down

0 comments on commit 7a751db

Please sign in to comment.