diff LazyBear/Views/Home/HomeView.swift @ 337:31f2838b2de7

Improving API requests with DispatchGroup
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 01 Apr 2021 16:34:45 +0200
parents 6f904b166564
children 71a9c0e61783
line wrap: on
line diff
--- a/LazyBear/Views/Home/HomeView.swift	Wed Mar 31 20:42:44 2021 +0200
+++ b/LazyBear/Views/Home/HomeView.swift	Thu Apr 01 16:34:45 2021 +0200
@@ -21,32 +21,36 @@
         let dueDate = Date()
     
     var body: some View {
-        NavigationView {
-            List {
-                SectorRow(sectorPerformance: homeData.sectorPerformance)
+        if homeData.showView {
+            NavigationView {
+                List {
+                    SectorRow(sectorPerformance: homeData.sectorPerformance)
+                        .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)
+                    }
                     .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)
                 }
-                .listRowInsets(EdgeInsets())
-            }
-            .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)")
-            .navigationBarTitleDisplayMode(.inline)
-            .navigationViewStyle(StackNavigationViewStyle())
-            .toolbar {
-                ToolbarItem(placement: .navigationBarTrailing) {
-                    Button(action: { showTradingDates = true }) {
-                        Image(systemName: "calendar.badge.clock")
+                .onReceive(timer) {_ in homeData.request() }
+                .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)")
+                .navigationBarTitleDisplayMode(.inline)
+                .navigationViewStyle(StackNavigationViewStyle())
+                .toolbar {
+                    ToolbarItem(placement: .navigationBarTrailing) {
+                        Button(action: { showTradingDates = true }) {
+                            Image(systemName: "calendar.badge.clock")
+                        }
                     }
                 }
             }
-        }
-        .onAppear { homeData.get() }
-        .onReceive(timer) {_ in homeData.get() }
-        .sheet(isPresented: $showTradingDates) {
-            TradingDates(stringDates: homeData.holidayDates)
+            .sheet(isPresented: $showTradingDates) {
+//                TradingDates(stringDates: homeData.holidayDates)
+            }
+        } else {
+            ProgressView()
+                .onAppear { homeData.request() }
         }
     }
 }