diff 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
line wrap: on
line diff
--- a/LazyBear/Views/Company/Chart.swift	Sat May 15 19:54:20 2021 +0200
+++ b/LazyBear/Views/Company/Chart.swift	Thu May 20 21:04:49 2021 +0200
@@ -23,8 +23,9 @@
         if company.showChartView {
             VStack {
                 DatePicker(ranges: ranges, selectedRange: $selectedRange)
-                    .onChange(of: selectedRange, perform: { value in
-                        print(value.lowercased())
+                    .onChange(of: selectedRange, perform: { range in
+//                        let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)/range=\(range)"
+//                        company.request(url, .refresh, "chart")
                     })
                 
                 RoundedRectangle(cornerRadius: 15)
@@ -49,8 +50,8 @@
                             }
                             .padding([.top, .leading, .trailing])
                             
-                            if let intradayPrices = company.chartData.intradayPrices![symbol.uppercased()] {
-                                if let prices = intradayPrices.compactMap { $0.open } {  // Map without nil
+                            if let historicalPrices = company.chartData.historicalPrices {
+                                if let prices = historicalPrices.compactMap { $0.close } {  // Map without nil
                                     LineChartView(data: prices, dates: nil, hours: nil, dragGesture: true)
                                         .padding(.bottom)
                                 }
@@ -68,12 +69,12 @@
             .onDisappear { self.timer.upstream.connect().cancel() }  // Stop timer
             .onReceive(timer) { _ in
                 let url = "https://api.lazybear.app/company/chart/type=streaming/symbol=\(symbol)"
-                company.request(url, isInitRequest: false, "chart") }  // Receive timer notification
+                company.request(url, .streaming, "chart") }  // Receive timer notification
         } else {
             ProgressView()
                 .onAppear {
                     let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)"
-                    company.request(url, isInitRequest: true, "chart")
+                    company.request(url, .initial, "chart")
                 }
         }
     }