Mercurial > public > lazybear
comparison LazyBear/Views/Home/Helpers/StockSheetRow.swift @ 425:4effac4733b0
Changing keys from API responses
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 16 Jun 2021 13:46:01 +0200 |
parents | 6dd97877f575 |
children |
comparison
equal
deleted
inserted
replaced
424:6dd97877f575 | 425:4effac4733b0 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 import StockCharts | 9 import StockCharts |
10 | 10 |
11 struct StockSheetRow: View { | 11 struct StockSheetRow: View { |
12 var symbol: String | 12 var company: CompanyModel |
13 var company: QuoteModel | |
14 var intradayPrices: [Double]? | |
15 | 13 |
16 var body: some View { | 14 var body: some View { |
17 HStack { | 15 HStack { |
18 VStack(alignment: .leading) { | 16 VStack(alignment: .leading) { |
19 Text(symbol.capitalized.capitalized) | 17 Text(company.symbol.uppercased()) |
20 .fontWeight(.semibold) | 18 .fontWeight(.semibold) |
21 | 19 |
22 Text(company.companyName.capitalized) | 20 Text(company.companyName.capitalized) |
23 .font(.callout) | 21 .font(.callout) |
24 .fontWeight(.semibold) | 22 .fontWeight(.semibold) |
25 .opacity(0.6) | 23 .opacity(0.6) |
26 .lineLimit(1) | 24 .lineLimit(1) |
27 } | 25 } |
28 | 26 |
29 Spacer() | 27 Spacer() |
30 if let prices = intradayPrices { | 28 LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false) |
31 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) | 29 .frame(width: 80) |
32 .frame(width: 80) | 30 .padding(.vertical, 10) |
33 .padding(.vertical, 10) | 31 .padding(.horizontal) |
34 .padding(.leading) | 32 |
35 } | |
36 | 33 |
37 if let latestPrice = company.latestPrice, let changePercent = company.changePercent { | 34 if let latestPrice = company.latestPrice, let changePercent = company.changePercent { |
38 VStack(alignment: .trailing) { | 35 VStack(alignment: .trailing) { |
39 Text("\(latestPrice, specifier: "%.2f")") | 36 Text("\(latestPrice, specifier: "%.2f")") |
40 .foregroundColor(changePercent < 0 ? .red: .green) | 37 .foregroundColor(changePercent < 0 ? .red: .green) |
50 } | 47 } |
51 } | 48 } |
52 | 49 |
53 struct StockSheetRow_Previews: PreviewProvider { | 50 struct StockSheetRow_Previews: PreviewProvider { |
54 static var previews: some View { | 51 static var previews: some View { |
55 StockSheetRow( | 52 StockSheetRow(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])) |
56 symbol: "aapl", | |
57 company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) | |
58 ) | |
59 } | 53 } |
60 } | 54 } |