diff 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
line wrap: on
line diff
--- a/LazyBear/Views/Company/Insiders.swift	Sat Jun 05 19:05:13 2021 +0200
+++ b/LazyBear/Views/Company/Insiders.swift	Sun Jun 06 13:11:41 2021 +0200
@@ -13,11 +13,37 @@
     
     var body: some View {
         if company.showInsidersView {
-            
+            VStack(alignment: .leading) {
+                HStack {
+                    Text("Top net buyers")
+                        .font(.title3)
+                        .fontWeight(.semibold)
+                    
+                    Spacer()
+                    Button("See all", action: {  })
+                }
+                
+                if let insiderSummer = company.insidersData.insiderRoster {
+                    
+                    // Get total shares owned by the top 10 insiders
+                    let totalPositions =  insiderSummer.map { $0.position }.reduce(0, +)
+                    VStack(alignment: .leading, spacing: 20) {
+                        ForEach(insiderSummer.prefix(10), id: \.self) { insider in
+                            
+                            // Compute percentage of ownership for each insider
+                            let percentage = Double(insider.position) / Double(totalPositions)
+                            
+                            InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider)
+                                .onAppear { print(percentage) }
+                        }
+                    }
+                }
+            }
         } else {
             ProgressView()
                 .onAppear {
-                    // request API
+                   let url = "https://api.lazybear.app/company/insiders/symbol=\(symbol)"
+                    company.request(url, .initial, "insider")
                 }
         }
     }