changeset 377:d01859776fe6

ProfileView updated
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 21 Apr 2021 16:44:11 +0200
parents 8162ccc5ec5c
children 6802c2393203
files LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/ContentView.swift LazyBear/Views/Profile/Networking/Profile.swift LazyBear/Views/Profile/Networking/ProfileResponse.swift LazyBear/Views/Profile/ProfileView.swift
diffstat 5 files changed, 61 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/ContentView.swift	Wed Apr 21 16:43:57 2021 +0200
+++ b/LazyBear/ContentView.swift	Wed Apr 21 16:44:11 2021 +0200
@@ -19,16 +19,16 @@
                         Image(systemName: "house")
                         Text("Home")
                     }
-//                SearchView()
-//                    .tabItem {
-//                        Image(systemName: "magnifyingglass")
-//                        Text("Search")
-//                    }
-//                ProfileView()
-//                    .tabItem {
-//                        Image(systemName: "person")
-//                        Text("Profile")
-//                    }
+                SearchView()
+                    .tabItem {
+                        Image(systemName: "magnifyingglass")
+                        Text("Search")
+                    }
+                ProfileView()
+                    .tabItem {
+                        Image(systemName: "person")
+                        Text("Profile")
+                    }
 //                Text("The Last Tab")
 //                    .tabItem {
 //                        Image(systemName: "4.square.fill")
--- a/LazyBear/Views/Profile/Networking/Profile.swift	Wed Apr 21 16:43:57 2021 +0200
+++ b/LazyBear/Views/Profile/Networking/Profile.swift	Wed Apr 21 16:44:11 2021 +0200
@@ -7,24 +7,23 @@
 
 import SwiftUI
 
-//class Profile: ObservableObject {
-//    @Published var showView = false
-//    @Published var data = ProfileResponse()
-//    
-//    var streamingRequests = 0  // Count streaming requests
-//    
-//    func request(_ url: String) {
-//        genericRequest(url: url, model: ProfileResponse.self) { response in
-//            print(response)
-//            self.streamingRequests += 1
-//            
-//            // If is the first request -> init()
-//            if self.streamingRequests == 1 {
-//                self.data = response
-//            } else {
-//                // If not, request streaming data (without intradayPrices)
-//                self.data.quotes = response.quotes
-//            }
-//        }
-//    }
-//}
+class Profile: ObservableObject {
+    @Published var showView = false
+    @Published var data = ProfileResponse()
+    
+    var streamingRequests = 0  // Count streaming requests
+    
+    func request(_ url: String) {
+        genericRequest(url: url, model: ProfileResponse.self) { response in
+            self.streamingRequests += 1
+            
+            // If is the first request -> init()
+            if self.streamingRequests == 1 {
+                self.data = response
+            } else {
+                // If not, request streaming data (without intradayPrices)
+                self.data.quotes = response.quotes
+            }
+        }
+    }
+}
--- a/LazyBear/Views/Profile/Networking/ProfileResponse.swift	Wed Apr 21 16:43:57 2021 +0200
+++ b/LazyBear/Views/Profile/Networking/ProfileResponse.swift	Wed Apr 21 16:44:11 2021 +0200
@@ -7,21 +7,11 @@
 
 import SwiftUI
 
-//struct ProfileResponse: Codable {
-//    var intradayPrices: [String: NestedIntradayPricesModel]?  // String is each company symbol
-//    var quotes: [String: NestedQuoteModel]?  // String is each company symbol
-//    
-//    private enum CodingKeys : String, CodingKey {
-//        case intradayPrices = "intraday_prices"
-//        case quotes
-//    }
-//}
-//
-//
-//struct NestedQuoteModel: Codable {
-//    var nestedQuoteModel: QuoteModel
-//    
-//    private enum CodingKeys : String, CodingKey {
-//        case nestedQuoteModel = "quote"
-//    }
-//}
+struct ProfileResponse: Codable {
+  var intradayPrices: [String: [IntradayPriceModel]]?
+  var quotes: [String: QuoteModel]?
+  
+  private enum CodingKeys : String, CodingKey {
+        case intradayPrices = "intraday_prices"
+    }
+}
--- a/LazyBear/Views/Profile/ProfileView.swift	Wed Apr 21 16:43:57 2021 +0200
+++ b/LazyBear/Views/Profile/ProfileView.swift	Wed Apr 21 16:44:11 2021 +0200
@@ -7,26 +7,26 @@
 
 import SwiftUI
 
-//struct ProfileView: View {
-//    @ObservedObject var profile = Profile()
-//
-//    var body: some View {
-//        NavigationView {
-//            List {
-//                
-//
-//            }
-//            .navigationTitle("My profile")
-//            .navigationBarTitleDisplayMode(.inline)
-//            .onAppear {
-//                profile.request("https://api.lazybear.app/profile/init/symbols/aapl")
-//            }
-//        }
-//    }
-//}
-//
-//struct ProfileView_Previews: PreviewProvider {
-//    static var previews: some View {
-//        ProfileView()
-//    }
-//}
+struct ProfileView: View {
+    @ObservedObject var profile = Profile()
+
+    var body: some View {
+        NavigationView {
+            List {
+                
+
+            }
+            .navigationTitle("My profile")
+            .navigationBarTitleDisplayMode(.inline)
+            .onAppear {
+                profile.request("https://api.lazybear.app/profile/type=init/symbols=aapl,fb")
+            }
+        }
+    }
+}
+
+struct ProfileView_Previews: PreviewProvider {
+    static var previews: some View {
+        ProfileView()
+    }
+}