comparison 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
comparison
equal deleted inserted replaced
442:6eae10397501 443:ffbb1dbab531
1 //
2 // InsiderRosterHelper.swift
3 // LazyBear
4 //
5 // Created by Dennis Concepción Martín on 21/6/21.
6 //
7
8 import SwiftUI
9
10 struct InsiderRosterHelper: View {
11 var insiderRoster: [InsiderRosterModel]
12 @State private var showList = false
13
14 var body: some View {
15 VStack(alignment: .leading) {
16 HStack {
17 Text("Top 10 Insiders")
18 .font(.title)
19 .fontWeight(.semibold)
20
21 Spacer()
22 Button("See all", action: { showList = true } )
23 }
24 .padding(.bottom)
25
26 let totalPositions = insiderRoster.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by top 10 insiders
27 ForEach(insiderRoster.prefix(4), id: \.self) { insider in
28 let percentageOfWidth = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider
29 InsiderRosterRow(insider: insider, percentageOfWidth: CGFloat(percentageOfWidth))
30 Divider()
31 }
32 }
33 .padding()
34 .background(
35 CustomRectangleBox()
36 )
37 .sheet(isPresented: $showList) {
38 InsiderRosterList(insiderRoster: insiderRoster)
39 }
40 }
41 }
42
43 struct InsiderRosterHelper_Previews: PreviewProvider {
44 static var previews: some View {
45 InsiderRosterHelper(
46 insiderRoster:
47 [
48 InsiderRosterModel(
49 entityName: "Tim Cook",
50 position: 12345,
51 reportDate: 12345
52 )
53 ]
54 )
55 }
56 }