Mercurial > public > lazybear
comparison LazyBear/Views/Home/Helpers/StockRow.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 | 8c58ce834d95 |
comparison
equal
deleted
inserted
replaced
424:6dd97877f575 | 425:4effac4733b0 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 | 10 |
11 struct StockRow: View { | 11 struct StockRow: View { |
12 var list: [String: [String: QuoteModel]] | 12 var listName: String |
13 var intradayPrices: [String: [Double]]? | 13 var companies: [CompanyModel] |
14 var showWatchlistSheet: Bool? | |
14 | 15 |
15 @State private var showList = false | 16 @State private var showList = false |
17 @Environment(\.managedObjectContext) private var moc | |
16 | 18 |
17 var body: some View { | 19 var body: some View { |
18 let listName = list.first!.key | |
19 VStack(alignment: .leading) { | 20 VStack(alignment: .leading) { |
20 HStack(alignment: .bottom) { | 21 HStack(alignment: .bottom) { |
21 VStack(alignment: .leading) { | 22 VStack(alignment: .leading) { |
22 Text(adaptListTitle(listName)) | 23 Text(adaptListTitle(listName)) |
23 .font(.title3) | 24 .font(.title3) |
36 .padding(.horizontal) | 37 .padding(.horizontal) |
37 } | 38 } |
38 | 39 |
39 ScrollView(.horizontal, showsIndicators: false) { | 40 ScrollView(.horizontal, showsIndicators: false) { |
40 HStack(spacing: 20) { | 41 HStack(spacing: 20) { |
41 let companies = list[listName] | 42 ForEach(companies, id: \.self) { company in |
42 ForEach(Array(companies!.keys), id: \.self) { symbol in | 43 StockItem(company: company) |
43 StockItem(symbol: symbol, company: companies![symbol]!, intradayPrices: intradayPrices![symbol]) | |
44 } | 44 } |
45 } | 45 } |
46 .padding() | 46 .padding() |
47 } | 47 } |
48 .frame(height: 250) | 48 .frame(height: 250) |
49 } | 49 } |
50 .padding(.bottom) | 50 .padding(.bottom) |
51 .sheet(isPresented: $showList) { | 51 .sheet(isPresented: $showList) { |
52 StockSheet(listName: adaptListTitle(listName), companies: list[list.first!.key]!, intradayPrices: intradayPrices) | 52 if showWatchlistSheet ?? false { |
53 WatchlistSheet(listName: adaptListTitle(listName), companies: companies) | |
54 .environment(\.managedObjectContext, self.moc) | |
55 } else { | |
56 StockSheet(listName: adaptListTitle(listName), companies: companies) | |
57 } | |
53 } | 58 } |
54 } | 59 } |
55 | 60 |
56 /* | 61 /* |
57 Get list keys (mostactive, losers, active) and adapt them to diplay | 62 Get list keys (mostactive, losers, active) and adapt them to diplay |
67 | 72 |
68 | 73 |
69 struct StockRectangleRow_Previews: PreviewProvider { | 74 struct StockRectangleRow_Previews: PreviewProvider { |
70 static var previews: some View { | 75 static var previews: some View { |
71 StockRow( | 76 StockRow( |
72 list: ["mostactive": ["AAPL": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 130.3)]], | 77 listName: "mostactive", |
73 intradayPrices: ["AAPL": [130.2]] | 78 companies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])] |
74 ) | 79 ) |
75 } | 80 } |
76 } | 81 } |