comparison LazyBear/Views/Company/Chart.swift @ 401:f843c6382529

Add Enumeration to Networks files
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 20 May 2021 21:04:49 +0200
parents 6055a867d2b6
children 8357b101df67
comparison
equal deleted inserted replaced
400:6055a867d2b6 401:f843c6382529
21 21
22 var body: some View { 22 var body: some View {
23 if company.showChartView { 23 if company.showChartView {
24 VStack { 24 VStack {
25 DatePicker(ranges: ranges, selectedRange: $selectedRange) 25 DatePicker(ranges: ranges, selectedRange: $selectedRange)
26 .onChange(of: selectedRange, perform: { value in 26 .onChange(of: selectedRange, perform: { range in
27 print(value.lowercased()) 27 // let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)/range=\(range)"
28 // company.request(url, .refresh, "chart")
28 }) 29 })
29 30
30 RoundedRectangle(cornerRadius: 15) 31 RoundedRectangle(cornerRadius: 15)
31 .foregroundColor(Color(.secondarySystemBackground)) 32 .foregroundColor(Color(.secondarySystemBackground))
32 .frame(height: 270) 33 .frame(height: 270)
47 } 48 }
48 Spacer() 49 Spacer()
49 } 50 }
50 .padding([.top, .leading, .trailing]) 51 .padding([.top, .leading, .trailing])
51 52
52 if let intradayPrices = company.chartData.intradayPrices![symbol.uppercased()] { 53 if let historicalPrices = company.chartData.historicalPrices {
53 if let prices = intradayPrices.compactMap { $0.open } { // Map without nil 54 if let prices = historicalPrices.compactMap { $0.close } { // Map without nil
54 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: true) 55 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: true)
55 .padding(.bottom) 56 .padding(.bottom)
56 } 57 }
57 } 58 }
58 } 59 }
66 } 67 }
67 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer 68 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer
68 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer 69 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer
69 .onReceive(timer) { _ in 70 .onReceive(timer) { _ in
70 let url = "https://api.lazybear.app/company/chart/type=streaming/symbol=\(symbol)" 71 let url = "https://api.lazybear.app/company/chart/type=streaming/symbol=\(symbol)"
71 company.request(url, isInitRequest: false, "chart") } // Receive timer notification 72 company.request(url, .streaming, "chart") } // Receive timer notification
72 } else { 73 } else {
73 ProgressView() 74 ProgressView()
74 .onAppear { 75 .onAppear {
75 let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)" 76 let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)"
76 company.request(url, isInitRequest: true, "chart") 77 company.request(url, .initial, "chart")
77 } 78 }
78 } 79 }
79 } 80 }
80 } 81 }
81 82