Mercurial > public > lazybear
comparison LazyBear/Views/Company/Helpers/InsiderList.swift @ 417:5f21f7c23c5e
Add comments and clean code
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 11 Jun 2021 11:37:42 +0200 |
parents | 2984d8946342 |
children | c78d5b5b3bda |
comparison
equal
deleted
inserted
replaced
416:1662a41e2c1a | 417:5f21f7c23c5e |
---|---|
20 | 20 |
21 Spacer() | 21 Spacer() |
22 Button("See all", action: { showFullList = true }) | 22 Button("See all", action: { showFullList = true }) |
23 } | 23 } |
24 | 24 |
25 // Get total shares owned by the top 10 insiders | 25 let totalPositions = insiderSummary.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by the top 10 insiders |
26 let totalPositions = insiderSummary.map { $0.position ?? 0 }.reduce(0, +) | |
27 VStack(alignment: .leading, spacing: 20) { | 26 VStack(alignment: .leading, spacing: 20) { |
28 ForEach(insiderSummary.prefix(3), id: \.self) { insider in | 27 ForEach(insiderSummary.prefix(3), id: \.self) { insider in |
29 | 28 let percentage = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider |
30 // Compute percentage of ownership for each insider | |
31 let percentage = Double(insider.position ?? 0) / Double(totalPositions) | |
32 | |
33 InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider) | 29 InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider) |
34 } | 30 } |
35 } | 31 } |
36 } | 32 } |
37 .sheet(isPresented: $showFullList) { | 33 .sheet(isPresented: $showFullList) { |
41 } | 37 } |
42 | 38 |
43 struct InsiderList_Previews: PreviewProvider { | 39 struct InsiderList_Previews: PreviewProvider { |
44 static var previews: some View { | 40 static var previews: some View { |
45 InsiderList(insiderSummary: | 41 InsiderList(insiderSummary: |
46 [InsiderRosterModel(entityName: "Dennis Concepcion", position: 1234, reportDate: 1234567)] | 42 [ |
43 InsiderRosterModel( | |
44 entityName: "Dennis Concepcion", | |
45 position: 1234, | |
46 reportDate: 1234567 | |
47 ) | |
48 ] | |
47 ) | 49 ) |
48 } | 50 } |
49 } | 51 } |
50 | 52 |
51 struct InsiderFullList: View { | 53 struct InsiderFullList: View { |
53 @Environment(\.presentationMode) private var presentationInsiderFullList | 55 @Environment(\.presentationMode) private var presentationInsiderFullList |
54 | 56 |
55 var body: some View { | 57 var body: some View { |
56 NavigationView { | 58 NavigationView { |
57 ScrollView { | 59 ScrollView { |
58 // Get total shares owned by the top 10 insiders | 60 let totalPositions = insiderSummary.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by the top 10 insiders |
59 let totalPositions = insiderSummary.map { $0.position ?? 0 }.reduce(0, +) | |
60 VStack(alignment: .leading, spacing: 20) { | 61 VStack(alignment: .leading, spacing: 20) { |
61 ForEach(insiderSummary, id: \.self) { insider in | 62 ForEach(insiderSummary, id: \.self) { insider in |
62 | 63 let percentage = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider |
63 // Compute percentage of ownership for each insider | |
64 let percentage = Double(insider.position ?? 0) / Double(totalPositions) | |
65 | |
66 InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider) | 64 InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider) |
67 } | 65 } |
68 } | 66 } |
69 .padding() | 67 .padding() |
70 } | 68 } |