annotate LazyBear/Views/Company/CompanyView.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 8357b101df67
children 5f21f7c23c5e
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
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
13
399
5c99883c7964 Implementing networking in CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 398
diff changeset
14 @ObservedObject var company = Company()
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
15 @State private var showViewSelector = false
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
16
400
6055a867d2b6 Implementing Historical Prices in Company.swift
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 399
diff changeset
17 // Views
6055a867d2b6 Implementing Historical Prices in Company.swift
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 399
diff changeset
18 @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
19 @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
20
398
933546fa5651 Implementing CompanyView
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents:
diff changeset
21 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
22 ScrollView {
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
23 VStack {
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
24 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
25 .padding(.bottom)
402
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
26
8357b101df67 Implementing CompanyView in NavigationLinks
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 400
diff changeset
27 // Chart View
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 /*
c804ce7a1560 Implementing Insider networking
Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
parents: 402
diff changeset
46 Hide all views to show later the one tapped
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 }