comparison LazyBear/Views/Home/HomeView.swift @ 375:f3cb5bdea8e5

Update Codable requests in HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 21 Apr 2021 16:19:50 +0200
parents eb97439e46cd
children a7e2c5a7b4f6
comparison
equal deleted inserted replaced
374:d402bfa367c2 375:f3cb5bdea8e5
30 SectorRow(sectorPerformance: sectorPerformance) 30 SectorRow(sectorPerformance: sectorPerformance)
31 .listRowInsets(EdgeInsets()) 31 .listRowInsets(EdgeInsets())
32 } 32 }
33 33
34 if let lists = home.data.lists { 34 if let lists = home.data.lists {
35 ForEach(Array(lists.keys.sorted()), id: \.self) { listName in 35 if let gainers = lists.gainers {
36 if let intradayPrices = home.data.intradayPrices { 36 StockRow(listName: "Gainers", list: gainers, intradayPrices: home.data.intradayPrices)
37 StockRow(listName: listName, list: lists[listName]!, nestedIntradayPrices: intradayPrices) 37 .listRowInsets(EdgeInsets())
38 } else {
39 StockRow(listName: listName, list: lists[listName]!, nestedIntradayPrices: nil)
40 }
41 } 38 }
42 .listRowInsets(EdgeInsets()) 39 if let losers = lists.losers {
40 StockRow(listName: "Losers", list: losers, intradayPrices: home.data.intradayPrices)
41 .listRowInsets(EdgeInsets())
42 }
43 if let mostActive = lists.mostactive {
44 StockRow(listName: "Most active", list: mostActive, intradayPrices: home.data.intradayPrices)
45 .listRowInsets(EdgeInsets())
46 }
43 } 47 }
44
45 if let latestCurrencies = home.data.latestCurrencies { 48 if let latestCurrencies = home.data.latestCurrencies {
46 CurrencyRow(latestCurrencies: latestCurrencies) 49 CurrencyRow(latestCurrencies: latestCurrencies)
47 .listRowInsets(EdgeInsets()) 50 .listRowInsets(EdgeInsets())
48 } 51 }
49 } 52 }
50 .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/streaming") } 53 .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/type=streaming") }
51 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer 54 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer
52 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)") 55 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)")
53 .navigationBarTitleDisplayMode(.inline) 56 .navigationBarTitleDisplayMode(.inline)
54 .navigationViewStyle(StackNavigationViewStyle()) 57 .navigationViewStyle(StackNavigationViewStyle())
55 .toolbar { 58 .toolbar {
66 } 69 }
67 } 70 }
68 } else { 71 } else {
69 ProgressView() 72 ProgressView()
70 .onAppear { 73 .onAppear {
71 home.request("https://api.lazybear.app/home/init") 74 home.request("https://api.lazybear.app/home/type=init")
72 75
73 // Restart timer 76 // Restart timer
74 self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() 77 self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
75 } 78 }
76 79