comparison LazyBear/Views/Home/HomeView.swift @ 326:2fabdc393675

Testing networking in HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Tue, 30 Mar 2021 23:13:14 +0200
parents 3e64824cca3e
children 2dad5828ccf6
comparison
equal deleted inserted replaced
325:cc3ba74d543e 326:2fabdc393675
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct HomeView: View { 10 struct HomeView: View {
11 @ObservedObject var homeData = HomeData()
12 @State private var showTradingDates = false
13
14 static let taskDateFormat: DateFormatter = {
15 let formatter = DateFormatter()
16 formatter.dateStyle = .medium
17 return formatter
18 }()
19
20 let dueDate = Date()
11 21
12 var body: some View { 22 var body: some View {
13 NavigationView { 23 NavigationView {
14 List { 24 List {
15 SectorRow() 25 SectorRow(sectorPerformance: homeData.sectorPerformance)
16 .listRowInsets(EdgeInsets()) 26 .listRowInsets(EdgeInsets())
17 27
18 let keyTitles = ["Top gainers", "Top losers", "Most active"] 28 let keyTitles = ["Top gainers", "Top losers", "Most active"]
19 ForEach(keyTitles, id: \.self) { keyTitle in 29 ForEach(keyTitles, id: \.self) { keyTitle in
20 TopStockRow(keyTitle: keyTitle) 30 TopStockRow(keyTitle: keyTitle)
21 31
22 } 32 }
23 .listRowInsets(EdgeInsets()) 33 .listRowInsets(EdgeInsets())
24 } 34 }
25 .navigationTitle("Home") 35 .navigationTitle("\(dueDate, formatter: Self.taskDateFormat)")
26 .navigationBarTitleDisplayMode(.inline) 36 .navigationBarTitleDisplayMode(.inline)
27 .navigationViewStyle(StackNavigationViewStyle()) 37 .navigationViewStyle(StackNavigationViewStyle())
38 .toolbar {
39 ToolbarItem(placement: .navigationBarTrailing) {
40 Button(action: { showTradingDates = true }) {
41 Image(systemName: "calendar.badge.clock")
42 }
43 }
44
45 ToolbarItem(placement: .navigationBarLeading) {
46 Button(action: { homeData.getSectorPerformance() }) {
47 Text("Test recall")
48 }
49 }
50 }
51 }
52 .onAppear { homeData.getSectorPerformance() }
53 .sheet(isPresented: $showTradingDates) {
54 TradingDates()
28 } 55 }
29 } 56 }
30 } 57 }
31 58
32 struct HomeView_Previews: PreviewProvider { 59 struct HomeView_Previews: PreviewProvider {