Mercurial > public > lazybear
view 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 source
// // Insiders.swift // LazyBear // // Created by Dennis Concepción Martín on 23/5/21. // import SwiftUI struct Insiders: View { @ObservedObject var company: Company var symbol: String 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 { let url = "https://api.lazybear.app/company/insiders/symbol=\(symbol)" company.request(url, .initial, "insider") } } } } struct Insiders_Previews: PreviewProvider { static var previews: some View { Insiders(company: Company(), symbol: "aapl") } }