comparison LazyBear/Views/Profile/ProfileView.swift @ 389:db8bc3ed526a

Implementing add to watchlist feature from SearchView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 25 Apr 2021 16:42:26 +0200
parents 79c39987aaa4
children 6303385b3629
comparison
equal deleted inserted replaced
388:79c39987aaa4 389:db8bc3ed526a
10 10
11 struct ProfileView: View { 11 struct ProfileView: View {
12 @ObservedObject var profile = Profile() 12 @ObservedObject var profile = Profile()
13 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) 13 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: [])
14 var watchlistCompanies: FetchedResults<WatchlistCompany> 14 var watchlistCompanies: FetchedResults<WatchlistCompany>
15
16 // Refresh view when watchlistCompanies change
17 @State private var refreshing = false
18 private var didSave = NotificationCenter.default.publisher(for: .NSManagedObjectContextDidSave)
15 19
16 var body: some View { 20 var body: some View {
17 if profile.showView { 21 if profile.showView {
18 NavigationView { 22 NavigationView {
19 List { 23 List {
31 intradayPrices: profile.data.intradayPrices, 35 intradayPrices: profile.data.intradayPrices,
32 addOnDelete: true 36 addOnDelete: true
33 ) 37 )
34 .listRowInsets(EdgeInsets()) 38 .listRowInsets(EdgeInsets())
35 } 39 }
40 }
41 // The listener for refresh the view
42 .onReceive(self.didSave) { _ in
43 self.refreshing.toggle()
36 } 44 }
37 } 45 }
38 .navigationTitle("My profile") 46 .navigationTitle("My profile")
39 .navigationBarTitleDisplayMode(.inline) 47 .navigationBarTitleDisplayMode(.inline)
40 .toolbar { 48 .toolbar {