comparison LazyBear/Views/Profile/ProfileView.swift @ 441:417148200aaf

Change background color and minor UI updates
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sun, 20 Jun 2021 19:52:21 +0200
parents 5ca468751db2
children bb69f9d1d20f
comparison
equal deleted inserted replaced
440:01fa77358b82 441:417148200aaf
18 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() /// Set recurrent price request 18 @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() /// Set recurrent price request
19 19
20 var body: some View { 20 var body: some View {
21 if profile.showView { 21 if profile.showView {
22 NavigationView { 22 NavigationView {
23 List { 23 ScrollView(showsIndicators: false) {
24 if let apiCompanies = profile.data.quotes { 24 VStack {
25 let watchlistsNames = Array(Set(watchlistCompanies.map { $0.watchlistName })).sorted() /// Get watchlistsNames in Core Data 25 if let apiCompanies = profile.data.quotes {
26 ForEach(watchlistsNames, id: \.self) { watchlistName in 26 let watchlistsNames = Array(Set(watchlistCompanies.map { $0.watchlistName })).sorted() /// Get watchlistsNames in Core Data
27 let companies = createWatchlistRow(apiCompanies, watchlistCompanies, watchlistName) 27 ForEach(watchlistsNames, id: \.self) { watchlistName in
28 ProfileStockRow(watchlistName: watchlistName, companies: companies) 28 let companies = createWatchlistRow(apiCompanies, watchlistCompanies, watchlistName)
29 ProfileStockRow(watchlistName: watchlistName, companies: companies)
30 }
31 .listRowInsets(EdgeInsets())
32 .onAppear { /// Request API again when Core Data changes to update the list
33 refreshList()
34 }
29 } 35 }
30 .listRowInsets(EdgeInsets()) 36 }
31 .onAppear { /// Request API again when Core Data changes to update the list 37 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } /// Start timer
32 refreshList() 38 .onDisappear { self.timer.upstream.connect().cancel() } /// Stop timer
39 .onReceive(timer) { _ in
40 if !showCreateNewWatchlist {
41 prepareUrl(.streaming)
42 }
43 }
44 .navigationTitle("My profile")
45 .toolbar {
46 ToolbarItem(placement: .navigationBarTrailing) {
47 Button(action: { showCreateNewWatchlist = true }) {
48 Image(systemName: "plus")
49 }
33 } 50 }
34 } 51 }
35 } 52 }
36 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } /// Start timer 53 .background(Color("customBackground").edgesIgnoringSafeArea(.all))
37 .onDisappear { self.timer.upstream.connect().cancel() } /// Stop timer 54 .fullScreenCover(isPresented: $showCreateNewWatchlist) {
38 .onReceive(timer) { _ in 55 WatchlistCreator()
39 if !showCreateNewWatchlist { 56 .environment(\.managedObjectContext, self.moc)
40 prepareUrl(.streaming)
41 }
42 }
43 .navigationTitle("My profile")
44 .navigationBarTitleDisplayMode(.inline)
45 .toolbar {
46 ToolbarItem(placement: .navigationBarTrailing) {
47 Button(action: { showCreateNewWatchlist = true }) {
48 Image(systemName: "plus")
49 }
50 }
51 } 57 }
52 } 58 }
53 .fullScreenCover(isPresented: $showCreateNewWatchlist) { 59 .navigationViewStyle(StackNavigationViewStyle())
54 WatchlistCreator()
55 .environment(\.managedObjectContext, self.moc)
56 }
57 } else { 60 } else {
58 ProgressView() 61 ProgressView()
59 .onAppear { prepareUrl(.initial) } 62 .onAppear { prepareUrl(.initial) }
60 } 63 }
61 } 64 }