Mercurial > public > lazybear
comparison LazyBear/Views/Global Helpers/StockItem.swift @ 346:80bfa88c6b0f
Implementing Prop API
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 11 Apr 2021 19:55:47 +0200 |
parents | fde2b30c719e |
children | 5ccceb527178 |
comparison
equal
deleted
inserted
replaced
345:fde2b30c719e | 346:80bfa88c6b0f |
---|---|
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct StockItem: View { | 10 struct StockItem: View { |
11 var company: CompanyQuoteModel | 11 var company: QuoteModel |
12 var intradayPrices: [IntradayPricesResult] | 12 var intradayPrices: [IntradayPricesModel]? |
13 | 13 |
14 private let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url" | 14 private let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url" |
15 private let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key" | 15 private let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key" |
16 | 16 |
17 var body: some View { | 17 var body: some View { |
37 } | 37 } |
38 .padding(.horizontal) | 38 .padding(.horizontal) |
39 | 39 |
40 Spacer() | 40 Spacer() |
41 | 41 |
42 let prices = intradayPrices.compactMap { $0.open } | 42 if let prices = intradayPrices?.compactMap { $0.marketOpen } { |
43 if prices.isEmpty { | |
44 Text("No data available") | |
45 .font(.caption) | |
46 .opacity(0.6) | |
47 | |
48 Spacer() | |
49 } else { | |
50 LineView(data: prices) | 43 LineView(data: prices) |
51 .foregroundColor(company.changePercent < 0 ? .red: .green) | 44 .foregroundColor(company.changePercent < 0 ? .red: .green) |
52 .padding(.vertical) | 45 .padding(.vertical) |
53 .clipped() | 46 .clipped() |
54 } | 47 } |
55 | 48 |
56 } | 49 } |
57 ,alignment: .leading | 50 ,alignment: .leading |
58 ) | 51 ) |
59 .onAppear { } | |
60 } | 52 } |
61 } | 53 } |
62 | 54 |
63 struct StockItem_Previews: PreviewProvider { | 55 struct StockItem_Previews: PreviewProvider { |
64 static var previews: some View { | 56 static var previews: some View { |
65 StockItem(company: CompanyQuoteModel(companyName: "Akumin Inc", symbol: "AKU", latestPrice: 120.30, changePercent: 0.03), intradayPrices: [IntradayPricesResult(open: 130.3)]) | 57 StockItem( |
66 | 58 company: QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03), |
59 intradayPrices: [IntradayPricesModel(marketOpen: 130.3)] | |
60 ) | |
67 } | 61 } |
68 } | 62 } |