comparison LazyBear/Views/Company/Insiders.swift @ 407:c804ce7a1560

Implementing Insider networking
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 06 Jun 2021 13:11:41 +0200
parents 48b3d2a410d4
children f9611c94d636
comparison
equal deleted inserted replaced
406:09d05e48462f 407:c804ce7a1560
11 @ObservedObject var company: Company 11 @ObservedObject var company: Company
12 var symbol: String 12 var symbol: String
13 13
14 var body: some View { 14 var body: some View {
15 if company.showInsidersView { 15 if company.showInsidersView {
16 16 VStack(alignment: .leading) {
17 HStack {
18 Text("Top net buyers")
19 .font(.title3)
20 .fontWeight(.semibold)
21
22 Spacer()
23 Button("See all", action: { })
24 }
25
26 if let insiderSummer = company.insidersData.insiderRoster {
27
28 // Get total shares owned by the top 10 insiders
29 let totalPositions = insiderSummer.map { $0.position }.reduce(0, +)
30 VStack(alignment: .leading, spacing: 20) {
31 ForEach(insiderSummer.prefix(10), id: \.self) { insider in
32
33 // Compute percentage of ownership for each insider
34 let percentage = Double(insider.position) / Double(totalPositions)
35
36 InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider)
37 .onAppear { print(percentage) }
38 }
39 }
40 }
41 }
17 } else { 42 } else {
18 ProgressView() 43 ProgressView()
19 .onAppear { 44 .onAppear {
20 // request API 45 let url = "https://api.lazybear.app/company/insiders/symbol=\(symbol)"
46 company.request(url, .initial, "insider")
21 } 47 }
22 } 48 }
23 } 49 }
24 } 50 }
25 51