comparison LazyBear/Views/Company/Chart.swift @ 415:34f9e408b861

Minor UI Updates and tests
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 09 Jun 2021 12:49:17 +0200
parents 2984d8946342
children 5f21f7c23c5e
comparison
equal deleted inserted replaced
414:b93172662988 415:34f9e408b861
16 var ranges = ["1D", "5D", "1M", "3M", "6M", "1Y", "5Y"] 16 var ranges = ["1D", "5D", "1M", "3M", "6M", "1Y", "5Y"]
17 @State private var selectedRange = "3M" 17 @State private var selectedRange = "3M"
18 18
19 // Set recurrent price request 19 // Set recurrent price request
20 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() 20 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
21
22 @State private var showingStatistics = false
21 23
22 var body: some View { 24 var body: some View {
23 if company.showChartView { 25 if company.showChartView {
24 VStack { 26 VStack {
25 DatePicker(ranges: ranges, selectedRange: $selectedRange) 27 DatePicker(ranges: ranges, selectedRange: $selectedRange)
41 horizontalAlignment: .leading, 43 horizontalAlignment: .leading,
42 verticalAlignment: .center, 44 verticalAlignment: .center,
43 orientation: .HStack, 45 orientation: .HStack,
44 priceFont: .title3, 46 priceFont: .title3,
45 priceFontWeight: .semibold, 47 priceFontWeight: .semibold,
46 percentFont: .headline, 48 percentFont: .body,
47 percentFontWeight: .medium, 49 percentFontWeight: .semibold,
48 showBackground: true 50 showBackground: true
49 ) 51 )
50 PriceView(latestPrice: latestPrice, changePercent: changePercent, style: priceViewStyle) 52 PriceView(latestPrice: latestPrice, changePercent: changePercent, style: priceViewStyle)
51 } 53 }
52 Spacer() 54 Spacer()
55
56 if let _ = company.chartData.keyStats {
57 Button("See stats", action: { showingStatistics = true })
58 }
53 } 59 }
54 .padding([.top, .leading, .trailing]) 60 .padding([.top, .leading, .trailing])
55 61
56 Spacer() 62 Spacer()
57 if let historicalPrices = company.chartData.historicalPrices { 63 if let historicalPrices = company.chartData.historicalPrices {
70 NewsRow(new: new) 76 NewsRow(new: new)
71 } 77 }
72 } 78 }
73 .padding(.top) 79 .padding(.top)
74 } 80 }
81 }
82 .sheet(isPresented: $showingStatistics) {
83 StatsView(keyStats: company.chartData.keyStats!)
75 } 84 }
76 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer 85 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer
77 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer 86 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer
78 .onReceive(timer) { _ in 87 .onReceive(timer) { _ in
79 let url = "https://api.lazybear.app/company/chart/symbol=\(symbol)/type=streaming" 88 let url = "https://api.lazybear.app/company/chart/symbol=\(symbol)/type=streaming"