Mercurial > public > lazybear
changeset 375:f3cb5bdea8e5
Update Codable requests in HomeView
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Wed Apr 21 16:19:50 2021 +0200 @@ -16,7 +16,6 @@ 950D0E302618B34600D17AD7 /* BlurBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E2F2618B34600D17AD7 /* BlurBackground.swift */; }; 950D0E332618B44800D17AD7 /* HudManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E322618B44800D17AD7 /* HudManager.swift */; }; 950D0E362618B61000D17AD7 /* BackgroundShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E352618B61000D17AD7 /* BackgroundShadow.swift */; }; - 95115E982625D15900BDC0F8 /* CurrencyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95115E972625D15900BDC0F8 /* CurrencyModel.swift */; }; 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951490542610BD2B00BDEEB5 /* WelcomeView.swift */; }; 951566E72613A2B6007C0F36 /* TradingDates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951566E62613A2B6007C0F36 /* TradingDates.swift */; }; 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951566E92613A37C007C0F36 /* TradingDatesItem.swift */; }; @@ -32,10 +31,6 @@ 9550444626111EE5000E0BCB /* SectorItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9550444526111EE5000E0BCB /* SectorItem.swift */; }; 9550444926111FC9000E0BCB /* StockRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9550444826111FC9000E0BCB /* StockRow.swift */; }; 9550444C26111FED000E0BCB /* StockItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9550444B26111FED000E0BCB /* StockItem.swift */; }; - 955E732D26235561005652FF /* QuoteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E732C26235561005652FF /* QuoteModel.swift */; }; - 955E7330262355FD005652FF /* SectorPerformanceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E732F262355FD005652FF /* SectorPerformanceModel.swift */; }; - 955E733326235633005652FF /* IntradayPricesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E733226235633005652FF /* IntradayPricesModel.swift */; }; - 955E73362623565F005652FF /* TradingDatesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E73352623565F005652FF /* TradingDatesModel.swift */; }; 955E73392623568F005652FF /* Home.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E73382623568F005652FF /* Home.swift */; }; 955E733C262356F3005652FF /* HomeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955E733B262356F3005652FF /* HomeResponse.swift */; }; 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */; }; @@ -47,6 +42,11 @@ 95721DB4262787EF00EC527B /* ExtensiveList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DB3262787EF00EC527B /* ExtensiveList.swift */; }; 95721DB826278EC100EC527B /* CurrencyListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DB726278EC100EC527B /* CurrencyListItem.swift */; }; 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 958A735125E0170900FD7ECA /* CloudKit.framework */; }; + 95A07F5D26305A8F009865AA /* IntradayPricesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A07F5C26305A8F009865AA /* IntradayPricesModel.swift */; }; + 95A07F6226305A9B009865AA /* CurrencyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A07F6126305A9B009865AA /* CurrencyModel.swift */; }; + 95A07F6C26305AC6009865AA /* QuoteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A07F6B26305AC6009865AA /* QuoteModel.swift */; }; + 95A07F7126305AD5009865AA /* SectorPerformanceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A07F7026305AD5009865AA /* SectorPerformanceModel.swift */; }; + 95A07F7626305AE3009865AA /* TradingDatesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A07F7526305AE3009865AA /* TradingDatesModel.swift */; }; 95A5186A26185AAB0002D27C /* GenericRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A5186926185AAB0002D27C /* GenericRequest.swift */; }; 95A5188626186F590002D27C /* PriceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A5188526186F590002D27C /* PriceView.swift */; }; 95A7C066261639E0003E2EC1 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A7C065261639DF003E2EC1 /* SearchView.swift */; }; @@ -92,7 +92,6 @@ 950D0E2F2618B34600D17AD7 /* BlurBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurBackground.swift; sourceTree = "<group>"; }; 950D0E322618B44800D17AD7 /* HudManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudManager.swift; sourceTree = "<group>"; }; 950D0E352618B61000D17AD7 /* BackgroundShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundShadow.swift; sourceTree = "<group>"; }; - 95115E972625D15900BDC0F8 /* CurrencyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyModel.swift; sourceTree = "<group>"; }; 951490542610BD2B00BDEEB5 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; }; 951566E62613A2B6007C0F36 /* TradingDates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDates.swift; sourceTree = "<group>"; }; 951566E92613A37C007C0F36 /* TradingDatesItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDatesItem.swift; sourceTree = "<group>"; }; @@ -107,10 +106,6 @@ 9550444526111EE5000E0BCB /* SectorItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectorItem.swift; sourceTree = "<group>"; }; 9550444826111FC9000E0BCB /* StockRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StockRow.swift; sourceTree = "<group>"; }; 9550444B26111FED000E0BCB /* StockItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StockItem.swift; sourceTree = "<group>"; }; - 955E732C26235561005652FF /* QuoteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteModel.swift; sourceTree = "<group>"; }; - 955E732F262355FD005652FF /* SectorPerformanceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectorPerformanceModel.swift; sourceTree = "<group>"; }; - 955E733226235633005652FF /* IntradayPricesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntradayPricesModel.swift; sourceTree = "<group>"; }; - 955E73352623565F005652FF /* TradingDatesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDatesModel.swift; sourceTree = "<group>"; }; 955E73382623568F005652FF /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; }; 955E733B262356F3005652FF /* HomeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeResponse.swift; sourceTree = "<group>"; }; 95672B8B25DDA54700DCBE4A /* LazyBear.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LazyBear.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -125,6 +120,11 @@ 95721DB726278EC100EC527B /* CurrencyListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyListItem.swift; sourceTree = "<group>"; }; 958A734E25E016FD00FD7ECA /* LazyBear.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LazyBear.entitlements; sourceTree = "<group>"; }; 958A735125E0170900FD7ECA /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; + 95A07F5C26305A8F009865AA /* IntradayPricesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntradayPricesModel.swift; sourceTree = "<group>"; }; + 95A07F6126305A9B009865AA /* CurrencyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyModel.swift; sourceTree = "<group>"; }; + 95A07F6B26305AC6009865AA /* QuoteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteModel.swift; sourceTree = "<group>"; }; + 95A07F7026305AD5009865AA /* SectorPerformanceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectorPerformanceModel.swift; sourceTree = "<group>"; }; + 95A07F7526305AE3009865AA /* TradingDatesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDatesModel.swift; sourceTree = "<group>"; }; 95A5186926185AAB0002D27C /* GenericRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericRequest.swift; sourceTree = "<group>"; }; 95A5188526186F590002D27C /* PriceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceView.swift; sourceTree = "<group>"; }; 95A7C065261639DF003E2EC1 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; }; @@ -232,11 +232,11 @@ children = ( 954D7EA5260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift */, 954D7EA6260BBA6600A13C50 /* WatchlistCompany+CoreDataProperties.swift */, - 955E732C26235561005652FF /* QuoteModel.swift */, - 955E732F262355FD005652FF /* SectorPerformanceModel.swift */, - 955E733226235633005652FF /* IntradayPricesModel.swift */, - 955E73352623565F005652FF /* TradingDatesModel.swift */, - 95115E972625D15900BDC0F8 /* CurrencyModel.swift */, + 95A07F5C26305A8F009865AA /* IntradayPricesModel.swift */, + 95A07F6126305A9B009865AA /* CurrencyModel.swift */, + 95A07F6B26305AC6009865AA /* QuoteModel.swift */, + 95A07F7026305AD5009865AA /* SectorPerformanceModel.swift */, + 95A07F7526305AE3009865AA /* TradingDatesModel.swift */, ); path = "Global Models"; sourceTree = "<group>"; @@ -548,7 +548,6 @@ 9550444926111FC9000E0BCB /* StockRow.swift in Sources */, 9550444326111E7A000E0BCB /* SectorRow.swift in Sources */, 95721DB826278EC100EC527B /* CurrencyListItem.swift in Sources */, - 955E7330262355FD005652FF /* SectorPerformanceModel.swift in Sources */, 950D0E302618B34600D17AD7 /* BlurBackground.swift in Sources */, 95ECCA60261216D500A67EFA /* LineView.swift in Sources */, 9550443A26111B2B000E0BCB /* HomeView.swift in Sources */, @@ -566,25 +565,26 @@ 9550444C26111FED000E0BCB /* StockItem.swift in Sources */, 950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */, 952994822629CA46005F0AB0 /* SearchResponse.swift in Sources */, + 95A07F6C26305AC6009865AA /* QuoteModel.swift in Sources */, 950D0E362618B61000D17AD7 /* BackgroundShadow.swift in Sources */, - 955E732D26235561005652FF /* QuoteModel.swift in Sources */, + 95A07F6226305A9B009865AA /* CurrencyModel.swift in Sources */, 9529947E2629CA3E005F0AB0 /* Search.swift in Sources */, 950D0E292618AEC800D17AD7 /* SearchedCompanyItem.swift in Sources */, 955E733C262356F3005652FF /* HomeResponse.swift in Sources */, - 955E733326235633005652FF /* IntradayPricesModel.swift in Sources */, 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */, 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */, 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */, + 95A07F7126305AD5009865AA /* SectorPerformanceModel.swift in Sources */, 9550444626111EE5000E0BCB /* SectorItem.swift in Sources */, 954D7EA7260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift in Sources */, 95672B9B25DDA54800DCBE4A /* LazyBear.xcdatamodeld in Sources */, 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */, 95AD4A2D26078C1400498079 /* ContentView.swift in Sources */, - 95115E982625D15900BDC0F8 /* CurrencyModel.swift in Sources */, 95721DB4262787EF00EC527B /* ExtensiveList.swift in Sources */, 95C8C0DB262A36990082D1D9 /* Profile.swift in Sources */, - 955E73362623565F005652FF /* TradingDatesModel.swift in Sources */, 952045152610C7C600A76362 /* ConvertEpoch.swift in Sources */, + 95A07F5D26305A8F009865AA /* IntradayPricesModel.swift in Sources */, + 95A07F7626305AE3009865AA /* TradingDatesModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/ContentView.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/ContentView.swift Wed Apr 21 16:19:50 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/Global Models/CurrencyModel.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Global Models/CurrencyModel.swift Wed Apr 21 16:19:50 2021 +0200 @@ -2,14 +2,13 @@ // CurrencyModel.swift // LazyBear // -// Created by Dennis Concepción Martín on 13/4/21. +// Created by Dennis Concepción Martín on 21/4/21. // import SwiftUI - struct CurrencyModel: Codable { - var flag: String - var name: String - var rate: Double + var flag: String + var name: String + var rate: Double }
--- a/LazyBear/Global Models/IntradayPricesModel.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Global Models/IntradayPricesModel.swift Wed Apr 21 16:19:50 2021 +0200 @@ -2,11 +2,11 @@ // IntradayPricesModel.swift // LazyBear // -// Created by Dennis Concepción Martín on 11/4/21. +// Created by Dennis Concepción Martín on 21/4/21. // import SwiftUI -struct IntradayPricesModel: Codable { - var open: Double? +struct IntradayPriceModel: Codable { + var open: Double }
--- a/LazyBear/Global Models/QuoteModel.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Global Models/QuoteModel.swift Wed Apr 21 16:19:50 2021 +0200 @@ -2,14 +2,13 @@ // QuoteModel.swift // LazyBear // -// Created by Dennis Concepción Martín on 11/4/21. +// Created by Dennis Concepción Martín on 21/4/21. // import SwiftUI -struct QuoteModel: Codable, Hashable { - var companyName: String - var symbol: String - var latestPrice: Double - var changePercent: Double +struct QuoteModel: Codable { + var changePercent: Double + var companyName: String + var latestPrice: Double }
--- a/LazyBear/Global Models/SectorPerformanceModel.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Global Models/SectorPerformanceModel.swift Wed Apr 21 16:19:50 2021 +0200 @@ -2,12 +2,12 @@ // SectorPerformanceModel.swift // LazyBear // -// Created by Dennis Concepción Martín on 11/4/21. +// Created by Dennis Concepción Martín on 21/4/21. // import SwiftUI struct SectorPerformanceModel: Codable, Hashable { - var name: String - var performance: Double + var name: String + var performance: Double }
--- a/LazyBear/Global Models/TradingDatesModel.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Global Models/TradingDatesModel.swift Wed Apr 21 16:19:50 2021 +0200 @@ -2,11 +2,11 @@ // TradingDatesModel.swift // LazyBear // -// Created by Dennis Concepción Martín on 11/4/21. +// Created by Dennis Concepción Martín on 21/4/21. // import SwiftUI struct TradingDatesModel: Codable { - var date: String + var date: String }
--- a/LazyBear/Views/Global Helpers/StockItem.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Global Helpers/StockItem.swift Wed Apr 21 16:19:50 2021 +0200 @@ -12,15 +12,16 @@ } struct StockItem: View { + var symbol: String var company: QuoteModel - var intradayPrices: [IntradayPricesModel]? + var intradayPrices: [IntradayPriceModel]? var orientation: OrientationView var body: some View { if orientation == .vertical { - return AnyView(VerticalStockRow(company: company, intradayPrices: intradayPrices)) + return AnyView(VerticalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices)) } else { - return AnyView(HorizontalStockRow(company: company, intradayPrices: intradayPrices)) + return AnyView(HorizontalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices)) } } } @@ -28,16 +29,17 @@ struct StockItem_Previews: PreviewProvider { static var previews: some View { StockItem( - company: QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03), - intradayPrices: [IntradayPricesModel(open: 130.3), IntradayPricesModel(open: 132.3)], orientation: .horizontal + symbol: "AAPL", company: QuoteModel(changePercent: 0.03, companyName: "apple inc", latestPrice: 130.3), + intradayPrices: [IntradayPriceModel(open: 130.3), IntradayPriceModel(open: 132.3)], orientation: .horizontal ) } } struct VerticalStockRow: View { + var symbol: String var company: QuoteModel - var intradayPrices: [IntradayPricesModel]? + var intradayPrices: [IntradayPriceModel]? var body: some View { RoundedRectangle(cornerRadius: 20) @@ -47,7 +49,7 @@ .overlay( VStack(alignment: .leading) { Group { - Text(company.symbol.uppercased()) + Text(symbol.uppercased()) .fontWeight(.semibold) .padding(.top) @@ -80,13 +82,14 @@ struct HorizontalStockRow: View { + var symbol: String var company: QuoteModel - var intradayPrices: [IntradayPricesModel]? + var intradayPrices: [IntradayPriceModel]? var body: some View { HStack { VStack(alignment: .leading) { - Text(company.symbol.uppercased()) + Text(symbol.uppercased()) .fontWeight(.semibold) Text(company.companyName.capitalized)
--- a/LazyBear/Views/Global Helpers/StockRow.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Global Helpers/StockRow.swift Wed Apr 21 16:19:50 2021 +0200 @@ -10,8 +10,8 @@ struct StockRow: View { var listName: String - var list: [QuoteModel] - var nestedIntradayPrices: [String: NestedIntradayPricesModel]? + var list: [String: QuoteModel] + var intradayPrices: [String: [IntradayPriceModel]]? @State private var showExtensiveList = false @@ -19,7 +19,7 @@ VStack(alignment: .leading) { HStack(alignment: .bottom) { VStack(alignment: .leading) { - Text(adaptTitle(listName)) + Text(listName) .font(.title3) .fontWeight(.semibold) .padding([.top, .horizontal]) @@ -38,12 +38,8 @@ ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { - ForEach(list, id: \.self) { company in - if let intradayPrices = nestedIntradayPrices?[company.symbol.uppercased()] { - StockItem(company: company, intradayPrices: intradayPrices.nestedIntradayPrices, orientation: .vertical) - } else { - StockItem(company: company, intradayPrices: nil, orientation: .vertical) - } + ForEach(Array(list.keys.sorted()), id: \.self) { companySymbol in + StockItem(symbol: companySymbol, company: list[companySymbol]!, intradayPrices: intradayPrices?[companySymbol], orientation: .vertical) } } .padding() @@ -52,26 +48,18 @@ } .padding(.bottom) .sheet(isPresented: $showExtensiveList) { - ExtensiveList(listName: adaptTitle(listName), list: list, nestedIntradayPrices: nestedIntradayPrices, latestCurrencies: nil) + ExtensiveList(listName: listName, list: list, intradayPrices: intradayPrices, latestCurrencies: nil) } } } -private func adaptTitle(_ listType: String) -> String { - if listType == "mostactive" { - return "Most active" - } else { - return listType.capitalized - } -} - struct StockRectangleRow_Previews: PreviewProvider { static var previews: some View { StockRow( - listName: "mostactive", - list: [QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03)], - nestedIntradayPrices: ["AAPL": NestedIntradayPricesModel(nestedIntradayPrices: [IntradayPricesModel(open: 130.3)])] + listName: "Gainers", + list: ["AAPL": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 130.3)], + intradayPrices: ["AAPL": [IntradayPriceModel(open: 130.2)]] ) } }
--- a/LazyBear/Views/Home/ExtensiveList.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Home/ExtensiveList.swift Wed Apr 21 16:19:50 2021 +0200 @@ -8,14 +8,9 @@ import SwiftUI struct ExtensiveList: View { - // General argument var listName: String - - // Arguments for lists - var list: [QuoteModel]? - var nestedIntradayPrices: [String: NestedIntradayPricesModel]? - - // Arguments for currencies + var list: [String: QuoteModel]? + var intradayPrices: [String: [IntradayPriceModel]]? var latestCurrencies: [String: CurrencyModel]? @Environment(\.presentationMode) var extensiveListPresent @@ -24,17 +19,13 @@ NavigationView { VStack { if let list = list { - List(list, id: \.self) { company in - if let intradayPrices = nestedIntradayPrices?[company.symbol.uppercased()] { - StockItem(company: company, intradayPrices: intradayPrices.nestedIntradayPrices, orientation: .horizontal) - } else { - StockItem(company: company, intradayPrices: nil, orientation: .horizontal) - } + List(Array(list.keys.sorted()), id: \.self) { companySymbol in + StockItem(symbol: companySymbol, company: list[companySymbol]!, intradayPrices: intradayPrices?[companySymbol], orientation: .horizontal) } } if let latestCurrencies = latestCurrencies { - List(Array(latestCurrencies.keys), id: \.self) { currencySymbol in + List(Array(latestCurrencies.keys.sorted()), id: \.self) { currencySymbol in CurrencyListItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!) } }
--- a/LazyBear/Views/Home/Helpers/CurrencyRow.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencyRow.swift Wed Apr 21 16:19:50 2021 +0200 @@ -43,7 +43,7 @@ } } .sheet(isPresented: $showExtensiveList) { - ExtensiveList(listName: "Currencies", list: nil, nestedIntradayPrices: nil, latestCurrencies: latestCurrencies) + ExtensiveList(listName: "Currencies", latestCurrencies: latestCurrencies) } } }
--- a/LazyBear/Views/Home/Helpers/SectorItem.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/SectorItem.swift Wed Apr 21 16:19:50 2021 +0200 @@ -37,8 +37,8 @@ } } -struct SectorItem_Previews: PreviewProvider { - static var previews: some View { - SectorItem(sector: SectorPerformanceModel(name: "Technology", performance: 0.04)) - } -} +//struct SectorItem_Previews: PreviewProvider { +// static var previews: some View { +// SectorItem(sector: SectorPerformanceModel(name: "Technology", performance: 0.04)) +// } +//}
--- a/LazyBear/Views/Home/HomeView.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Home/HomeView.swift Wed Apr 21 16:19:50 2021 +0200 @@ -32,22 +32,25 @@ } if let lists = home.data.lists { - ForEach(Array(lists.keys.sorted()), id: \.self) { listName in - if let intradayPrices = home.data.intradayPrices { - StockRow(listName: listName, list: lists[listName]!, nestedIntradayPrices: intradayPrices) - } else { - StockRow(listName: listName, list: lists[listName]!, nestedIntradayPrices: nil) - } + if let gainers = lists.gainers { + StockRow(listName: "Gainers", list: gainers, intradayPrices: home.data.intradayPrices) + .listRowInsets(EdgeInsets()) } - .listRowInsets(EdgeInsets()) + if let losers = lists.losers { + StockRow(listName: "Losers", list: losers, intradayPrices: home.data.intradayPrices) + .listRowInsets(EdgeInsets()) + } + if let mostActive = lists.mostactive { + StockRow(listName: "Most active", list: mostActive, intradayPrices: home.data.intradayPrices) + .listRowInsets(EdgeInsets()) + } } - if let latestCurrencies = home.data.latestCurrencies { CurrencyRow(latestCurrencies: latestCurrencies) .listRowInsets(EdgeInsets()) } } - .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/streaming") } + .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/type=streaming") } .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)") .navigationBarTitleDisplayMode(.inline) @@ -68,7 +71,7 @@ } else { ProgressView() .onAppear { - home.request("https://api.lazybear.app/home/init") + home.request("https://api.lazybear.app/home/type=init") // Restart timer self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
--- a/LazyBear/Views/Home/Networking/HomeResponse.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Home/Networking/HomeResponse.swift Wed Apr 21 16:19:50 2021 +0200 @@ -8,26 +8,24 @@ import SwiftUI struct HomeResponse: Codable { - var lists: [String: [QuoteModel]]? // String is the list type; gainers, losers ... - var sectorPerformance: [SectorPerformanceModel]? - var tradingDates: [TradingDatesModel]? - var intradayPrices: [String: NestedIntradayPricesModel]? // String is each company symbol - var latestCurrencies: [String: CurrencyModel]? - - private enum CodingKeys : String, CodingKey { + var intradayPrices: [String: [IntradayPriceModel]]? + var latestCurrencies: [String: CurrencyModel]? + var lists: ListsModel? + var sectorPerformance: [SectorPerformanceModel]? + var tradingDates: [TradingDatesModel]? + + private enum CodingKeys : String, CodingKey { + case intradayPrices = "intraday_prices" + case latestCurrencies = "latest_currencies" case lists case sectorPerformance = "sector_performance" case tradingDates = "trading_dates" - case intradayPrices = "intraday_prices" - case latestCurrencies = "latest_currencies" } } -struct NestedIntradayPricesModel: Codable { - var nestedIntradayPrices: [IntradayPricesModel] - - private enum CodingKeys : String, CodingKey { - case nestedIntradayPrices = "intradayprices" - } +struct ListsModel: Codable { + var mostactive: [String: QuoteModel]? + var gainers: [String: QuoteModel]? + var losers: [String: QuoteModel]? }
--- a/LazyBear/Views/Profile/Networking/Profile.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Profile/Networking/Profile.swift Wed Apr 21 16:19:50 2021 +0200 @@ -7,24 +7,24 @@ 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 +// 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 +// } +// } +// } +//}
--- a/LazyBear/Views/Profile/Networking/ProfileResponse.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Profile/Networking/ProfileResponse.swift Wed Apr 21 16:19:50 2021 +0200 @@ -7,21 +7,21 @@ 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: 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" +// } +//}
--- a/LazyBear/Views/Profile/ProfileView.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Profile/ProfileView.swift Wed Apr 21 16:19:50 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/init/symbols/aapl") +// } +// } +// } +//} +// +//struct ProfileView_Previews: PreviewProvider { +// static var previews: some View { +// ProfileView() +// } +//}
--- a/LazyBear/Views/Welcome/WelcomeView.swift Sat Apr 17 00:01:59 2021 +0200 +++ b/LazyBear/Views/Welcome/WelcomeView.swift Wed Apr 21 16:19:50 2021 +0200 @@ -16,7 +16,7 @@ VStack { Image("default") .resizable() - .frame(width: proxy.size.width*0.3, height: proxy.size.width*0.3) + .frame(width: proxy.size.width*0.25, height: proxy.size.width*0.25) .cornerRadius(25) .shadow(color: Color.black.opacity(0.3), radius: 10) .padding(.vertical)