annotate LazyBear/Views/Company/CompanyView.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 c804ce7a1560
children 277197ce1416
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
1 //
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
2 // CompanyView.swift
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
3 // LazyBear
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
4 //
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
5 // Created by Dennis Concepción Martín on 8/5/21.
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
6 //
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
7
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
8 import SwiftUI
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
9 import StockCharts
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
10
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
11 struct CompanyView: View {
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
12 var symbol: String
399
5c99883c7964 Implementing networking in CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 398
diff changeset
13 @ObservedObject var company = Company()
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
14 @State private var showViewSelector = false
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
15
417
5f21f7c23c5e Add comments and clean code
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 407
diff changeset
16 /*
5f21f7c23c5e Add comments and clean code
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 407
diff changeset
17 Views
5f21f7c23c5e Add comments and clean code
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 407
diff changeset
18 */
400
6055a867d2b6 Implementing Historical Prices in Company.swift
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 399
diff changeset
19 @State private var showChartView = true
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
20 @State private var showInsiderView = false
399
5c99883c7964 Implementing networking in CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 398
diff changeset
21
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
22 var body: some View {
402
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
23 ScrollView {
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
24 VStack {
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
25 CompanyHeader(symbol: symbol, showViewSelector: $showViewSelector)
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
26 .padding(.bottom)
417
5f21f7c23c5e Add comments and clean code
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 407
diff changeset
27
402
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
28 if showChartView {
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
29 Chart(company: company, symbol: symbol)
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
30 } else if showInsiderView {
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
31 Insiders(company: company, symbol: symbol)
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
32 }
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
33 }
402
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
34 .padding()
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
35 }
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
36 .actionSheet(isPresented: $showViewSelector) {
399
5c99883c7964 Implementing networking in CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 398
diff changeset
37 ActionSheet(title: Text("Select an option"), buttons: [
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
38 .default(Text("Chart & News")) { resetViews(); showChartView = true },
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
39 .default(Text("Insiders")) { resetViews(); showInsiderView = true },
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
40 .cancel()
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
41 ])
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
42 }
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
43 }
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
44
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
45 /*
417
5f21f7c23c5e Add comments and clean code
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 407
diff changeset
46 Hide all views to show the one selected by user
407
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
47 */
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
48 private func resetViews() {
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
49 showChartView = false
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
50 showInsiderView = false
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
51 }
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
52 }
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
53
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
54 struct CompanyView_Previews: PreviewProvider {
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
55 static var previews: some View {
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
56 CompanyView(symbol: "AAPL")
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
57 }
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
58 }