Mercurial > public > lazybear
diff LazyBear/Views/Company/CompanyView.swift @ 400:6055a867d2b6
Implementing Historical Prices in Company.swift
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 15 May 2021 19:54:20 +0200 |
parents | 5c99883c7964 |
children | 8357b101df67 |
line wrap: on
line diff
--- a/LazyBear/Views/Company/CompanyView.swift Sat May 15 12:31:40 2021 +0200 +++ b/LazyBear/Views/Company/CompanyView.swift Sat May 15 19:54:20 2021 +0200 @@ -12,11 +12,10 @@ var symbol: String @ObservedObject var company = Company() - @ObservedObject var viewSelector = ViewSelector() @State private var showViewSelector = false - // Set recurrent price request - @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() + // Views + @State private var showChartView = true var body: some View { NavigationView { @@ -24,23 +23,9 @@ VStack { CompanyHeader(symbol: symbol, showViewSelector: $showViewSelector) - // <--- Chart View ---> - if viewSelector.views["chart"]! { - let url = "https://api.lazybear.app/company/chart/type=init/symbol=\(symbol)" - - if company.showChartView { - Chart(chartData: company.chartData, symbol: symbol) - .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer - .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 - } - else { - ProgressView() - .onAppear { company.request(url, isInitRequest: true, "chart") } } - - // ---> Chart View <--- + // Chart View + if showChartView { + Chart(company: company, symbol: symbol) } } .padding() @@ -50,7 +35,7 @@ } .actionSheet(isPresented: $showViewSelector) { ActionSheet(title: Text("Select an option"), buttons: [ - .default(Text("Chart & News")) { viewSelector.showView(.chart) }, + .default(Text("Chart & News")) { showChartView = true }, .cancel() ]) }