Mercurial > public > lazybear
diff LazyBear/Views/Company/Helpers/InsiderRosterHelper.swift @ 443:ffbb1dbab531
InsiderRosterHelper implemented
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 21 Jun 2021 20:17:46 +0200 |
parents | |
children | 9cc0455bc46f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/InsiderRosterHelper.swift Mon Jun 21 20:17:46 2021 +0200 @@ -0,0 +1,56 @@ +// +// InsiderRosterHelper.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 21/6/21. +// + +import SwiftUI + +struct InsiderRosterHelper: View { + var insiderRoster: [InsiderRosterModel] + @State private var showList = false + + var body: some View { + VStack(alignment: .leading) { + HStack { + Text("Top 10 Insiders") + .font(.title) + .fontWeight(.semibold) + + Spacer() + Button("See all", action: { showList = true } ) + } + .padding(.bottom) + + let totalPositions = insiderRoster.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by top 10 insiders + ForEach(insiderRoster.prefix(4), id: \.self) { insider in + let percentageOfWidth = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider + InsiderRosterRow(insider: insider, percentageOfWidth: CGFloat(percentageOfWidth)) + Divider() + } + } + .padding() + .background( + CustomRectangleBox() + ) + .sheet(isPresented: $showList) { + InsiderRosterList(insiderRoster: insiderRoster) + } + } +} + +struct InsiderRosterHelper_Previews: PreviewProvider { + static var previews: some View { + InsiderRosterHelper( + insiderRoster: + [ + InsiderRosterModel( + entityName: "Tim Cook", + position: 12345, + reportDate: 12345 + ) + ] + ) + } +}