Mercurial > public > lazybear
comparison LazyBear/Views/Home/HomeView.swift @ 417:5f21f7c23c5e
Add comments and clean code
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 11 Jun 2021 11:37:42 +0200 |
parents | f843c6382529 |
children | a38e8acccb85 |
comparison
equal
deleted
inserted
replaced
416:1662a41e2c1a | 417:5f21f7c23c5e |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct HomeView: View { | 10 struct HomeView: View { |
11 @ObservedObject var home = Home() | 11 @ObservedObject var home = Home() |
12 | |
12 @State private var showTradingDates = false | 13 @State private var showTradingDates = false |
13 | 14 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() /// Set recurrent price request |
14 // Set recurrent price request | |
15 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() | |
16 | 15 |
17 static let taskDateFormat: DateFormatter = { | 16 static let taskDateFormat: DateFormatter = { |
18 let formatter = DateFormatter() | 17 let formatter = DateFormatter() |
19 formatter.dateStyle = .medium | 18 formatter.dateStyle = .medium |
20 return formatter | 19 return formatter |
30 SectorRow(sectorPerformance: sectorPerformance) | 29 SectorRow(sectorPerformance: sectorPerformance) |
31 .listRowInsets(EdgeInsets()) | 30 .listRowInsets(EdgeInsets()) |
32 } | 31 } |
33 | 32 |
34 if let lists = home.data.lists { | 33 if let lists = home.data.lists { |
35 if let gainers = lists.gainers { | 34 let mirror = Mirror(reflecting: lists) |
36 StockRow(listName: "Gainers", list: gainers, intradayPrices: home.data.intradayPrices, addOnDelete: false) | 35 ForEach(Array(mirror.children), id: \.label) { child in |
37 .listRowInsets(EdgeInsets()) | 36 if let list = child.value as? [String : QuoteModel] { |
38 } | 37 StockRow(listName: "\(child.label!)", list: list, intradayPrices: home.data.intradayPrices, addOnDelete: false) |
39 if let losers = lists.losers { | 38 .listRowInsets(EdgeInsets()) |
40 StockRow(listName: "Losers", list: losers, intradayPrices: home.data.intradayPrices, addOnDelete: false) | 39 } |
41 .listRowInsets(EdgeInsets()) | |
42 } | |
43 if let mostActive = lists.mostactive { | |
44 StockRow(listName: "Most active", list: mostActive, intradayPrices: home.data.intradayPrices, addOnDelete: false) | |
45 .listRowInsets(EdgeInsets()) | |
46 } | 40 } |
47 } | 41 } |
48 if let latestCurrencies = home.data.latestCurrencies { | 42 if let latestCurrencies = home.data.latestCurrencies { |
49 CurrencyRow(latestCurrencies: latestCurrencies) | 43 CurrencyRow(latestCurrencies: latestCurrencies) |
50 .listRowInsets(EdgeInsets()) | 44 .listRowInsets(EdgeInsets()) |
51 } | 45 } |
52 } | 46 } |
53 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer | 47 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } /// Restart timer |
54 .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/type=streaming", .streaming) } // Receive timer notification | 48 .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/type=streaming", .streaming) } /// Receive timer notification |
55 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer | 49 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer |
56 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)") | 50 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)") |
57 .navigationBarTitleDisplayMode(.inline) | 51 .navigationBarTitleDisplayMode(.inline) |
58 .navigationViewStyle(StackNavigationViewStyle()) | 52 .navigationViewStyle(StackNavigationViewStyle()) |
59 .toolbar { | 53 .toolbar { |