diff LazyBear/Views/Home/HomeView.swift @ 339:e81c18164afb

Fixing backend API Requests
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 03 Apr 2021 13:02:40 +0200
parents 71a9c0e61783
children 4e6c47a81b80
line wrap: on
line diff
--- a/LazyBear/Views/Home/HomeView.swift	Thu Apr 01 20:55:09 2021 +0200
+++ b/LazyBear/Views/Home/HomeView.swift	Sat Apr 03 13:02:40 2021 +0200
@@ -28,13 +28,15 @@
                         .listRowInsets(EdgeInsets())
                         
                     // Get keys of the dictionary list
-                    ForEach(homeData.list.keys.sorted(), id: \.self) { key in
-                        TopStockRow(key: key, list: homeData.list[key] ?? [CompanyRowModel](), intradayPricesDict: homeData.intradayPrices)
+                    ForEach(homeData.topLists.keys.sorted(), id: \.self) { listType in
+                        if let list = homeData.topLists[listType] {
+                            TopStockRow(listType: listType, list: list)
+                        }
                     }
                     .listRowInsets(EdgeInsets())
                 }
-                .onReceive(timer) {_ in homeData.request() }
-                .onDisappear { timer.upstream.connect().cancel() }
+                .onReceive(timer) { _ in homeData.request() }
+                .onDisappear { self.timer.upstream.connect().cancel() }  // Stop timer
                 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)")
                 .navigationBarTitleDisplayMode(.inline)
                 .navigationViewStyle(StackNavigationViewStyle())
@@ -47,11 +49,15 @@
                 }
             }
             .sheet(isPresented: $showTradingDates) {
-                TradingDates(stringDates: homeData.holidayDates)
+                TradingDates()
             }
         } else {
             ProgressView()
-                .onAppear { homeData.request() }
+                .onAppear {
+                    homeData.request()
+                    self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()  // Restart timer
+                }
+            
         }
     }
 }