Skip to content

Commit

Permalink
as
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocamargo committed Jun 4, 2021
1 parent 9e08c32 commit c22a9ea
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CupcakeCorner/CupcakeCorner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
0561612B2669CEFC009EA5B7 /* Order.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0561612A2669CEFC009EA5B7 /* Order.swift */; };
0561612D2669D2A6009EA5B7 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0561612C2669D2A6009EA5B7 /* AddressView.swift */; };
0561612F2669D3B6009EA5B7 /* CheckoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0561612E2669D3B6009EA5B7 /* CheckoutView.swift */; };
05B50C5E2669C41300F05354 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B50C5D2669C41300F05354 /* AppDelegate.swift */; };
05B50C602669C41300F05354 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B50C5F2669C41300F05354 /* SceneDelegate.swift */; };
05B50C622669C41300F05354 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B50C612669C41300F05354 /* ContentView.swift */; };
Expand All @@ -16,6 +19,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0561612A2669CEFC009EA5B7 /* Order.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Order.swift; sourceTree = "<group>"; };
0561612C2669D2A6009EA5B7 /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
0561612E2669D3B6009EA5B7 /* CheckoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckoutView.swift; sourceTree = "<group>"; };
05B50C5A2669C41300F05354 /* CupcakeCorner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CupcakeCorner.app; sourceTree = BUILT_PRODUCTS_DIR; };
05B50C5D2669C41300F05354 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
05B50C5F2669C41300F05354 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -63,6 +69,9 @@
05B50C682669C41600F05354 /* LaunchScreen.storyboard */,
05B50C6B2669C41600F05354 /* Info.plist */,
05B50C652669C41600F05354 /* Preview Content */,
0561612A2669CEFC009EA5B7 /* Order.swift */,
0561612C2669D2A6009EA5B7 /* AddressView.swift */,
0561612E2669D3B6009EA5B7 /* CheckoutView.swift */,
);
path = CupcakeCorner;
sourceTree = "<group>";
Expand Down Expand Up @@ -145,8 +154,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0561612D2669D2A6009EA5B7 /* AddressView.swift in Sources */,
05B50C5E2669C41300F05354 /* AppDelegate.swift in Sources */,
0561612F2669D3B6009EA5B7 /* CheckoutView.swift in Sources */,
05B50C602669C41300F05354 /* SceneDelegate.swift in Sources */,
0561612B2669CEFC009EA5B7 /* Order.swift in Sources */,
05B50C622669C41300F05354 /* ContentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
36 changes: 36 additions & 0 deletions CupcakeCorner/CupcakeCorner/AddressView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AddressUIView.swift
// CupcakeCorner
//
// Created by joao camargo on 04/06/21.
//

import SwiftUI

struct AddressView: View {

@ObservedObject var order : Order

var body: some View {
Form {
Section {
TextField("Name", text: $order.name)
TextField("Street Address", text: $order.streetAddress)
TextField("City", text: $order.city)
TextField("Zip", text: $order.zip)
}

Section {
NavigationLink(destination: CheckoutView(order: order)) {
Text("Checkout")
}
}.disabled(!order.hasValidAddress)
} .navigationBarTitle("Delivery details", displayMode: .inline)
}
}

struct AddressUIView_Previews: PreviewProvider {
static var previews: some View {
AddressView(order: Order())
}
}
23 changes: 23 additions & 0 deletions CupcakeCorner/CupcakeCorner/CheckoutView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CheckoutView.swift
// CupcakeCorner
//
// Created by joao camargo on 04/06/21.
//

import SwiftUI

struct CheckoutView: View {

@ObservedObject var order: Order

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}

struct CheckoutView_Previews: PreviewProvider {
static var previews: some View {
CheckoutView(order: Order())
}
}
112 changes: 110 additions & 2 deletions CupcakeCorner/CupcakeCorner/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,119 @@

import SwiftUI

//class User: ObservableObject, Codable {
//
//
// enum CodingKeys: CodingKey {
// case name
// }
//
// @Published var name = "Joao Camargo"
//
// required init(from decoder: Decoder) throws {
// let container = try decoder.container(keyedBy: CodingKeys.self)
// name = try container.decode(String.self, forKey: .name)
// }
//
// func encode(to encoder: Encoder) throws {
// var container = encoder.container(keyedBy: CodingKeys.self)
// try container.encode(name, forKey: .name)
// }
//
//}



//@State var results = [Result]()
//
//
//var body: some View {
// List(results, id: \.trackId) { item in
// VStack(alignment: .leading) {
// Text(item.trackName).font(.headline)
// Text(item.collectionName)
// }
// }.onAppear(perform: loadData)
//}
//
//func loadData() {
// guard let url = URL(string: "https://itunes.apple.com/search?term=taylor+swift&entity=song") else {
// print("Invalid URL")
// return
// }
//
// let request = URLRequest(url: url)
// URLSession.shared.dataTask(with: request) { data, response, error in
// if let data = data {
// if let decodedResponse = try? JSONDecoder().decode(Response.self, from: data) {
// DispatchQueue.main.async {
// self.results = decodedResponse.results
// }
// return
// }
// }
// print("Fetch failed: \(error?.localizedDescription ?? "Unknow error")")
// }.resume()
//
//}

struct Response: Codable {
var results: [Result]
}

struct Result: Codable {
var trackId: Int
var trackName: String
var collectionName: String
}


struct ContentView: View {
@ObservedObject var order = Order()

var body: some View {
Text("Hello, world!")
.padding()
NavigationView {
Form {
Section {
Picker("Select your cake type",selection: $order.type) {
ForEach(0..<Order.types.count){
Text(Order.types[$0])
}
}
Stepper(value: $order.quantity,in: 3...20) {
Text("Number of cakes: \(order.quantity)")

}
}

Section {
Toggle(isOn: $order.specialRequestEnabled.animation()) {
Text("Any request?")
}

if order.specialRequestEnabled {
Toggle(isOn: $order.extraFrosting) {
Text("add extra frosting")
}

Toggle(isOn: $order.addSprinkles) {
Text("add extra sprinkels")
}
}
}

Section {
NavigationLink(destination: AddressView(order: order)) {
Text("Delivery Details")
}
}
}
.navigationBarTitle("Cupcake Corner")

}
}


}

struct ContentView_Previews: PreviewProvider {
Expand Down
40 changes: 40 additions & 0 deletions CupcakeCorner/CupcakeCorner/Order.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Order.swift
// CupcakeCorner
//
// Created by joao camargo on 04/06/21.
//

import Foundation

class Order: ObservableObject {
static let types = ["Vanilla", "Strawberry","Chocolate","Rainbow"]


@Published var type = 0
@Published var quantity = 3

@Published var specialRequestEnabled = false {
didSet {
if !specialRequestEnabled {
extraFrosting = false
addSprinkles = false
}
}
}
@Published var extraFrosting = false
@Published var addSprinkles = false

@Published var name = ""
@Published var streetAddress = ""
@Published var city = ""
@Published var zip = ""

var hasValidAddress: Bool {
if name.isEmpty || streetAddress.isEmpty || city.isEmpty || zip.isEmpty {
return false
}
return true
}

}

0 comments on commit c22a9ea

Please sign in to comment.