comparison LazyBear/Views/Profile/ProfileView.swift @ 391:8ec37b2baafd

Implementing CreateNewWatchlist
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Fri, 30 Apr 2021 20:25:52 +0200
parents 6303385b3629
children 13f3578def61
comparison
equal deleted inserted replaced
390:6303385b3629 391:8ec37b2baafd
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 @State private var showCreateNewWatchlist = false
15 17
16 var body: some View { 18 var body: some View {
17 if profile.showView { 19 if profile.showView {
18 NavigationView { 20 NavigationView {
19 // Get Watchlist names -> Create rows for each watchlist -> in each row, show companies
20 List { 21 List {
22
23 // Get Watchlist names -> Create rows for each watchlist -> in each row, show companies
21 let watchlists = Set(watchlistCompanies.map { $0.watchlist }) // Set -> avoid duplicates names 24 let watchlists = Set(watchlistCompanies.map { $0.watchlist }) // Set -> avoid duplicates names
22 25
23 ForEach(Array(watchlists), id: \.self) { watchlist in 26 ForEach(Array(watchlists), id: \.self) { watchlist in
24 let symbols = watchlistCompanies.filter({ $0.watchlist == watchlist }).map { $0.symbol } 27 let symbols = watchlistCompanies.filter({ $0.watchlist == watchlist }).map { $0.symbol }
25 28
37 } 40 }
38 .navigationTitle("My profile") 41 .navigationTitle("My profile")
39 .navigationBarTitleDisplayMode(.inline) 42 .navigationBarTitleDisplayMode(.inline)
40 .toolbar { 43 .toolbar {
41 ToolbarItem(placement: .navigationBarTrailing) { 44 ToolbarItem(placement: .navigationBarTrailing) {
42 Button(action: {}) { 45 Button(action: { showCreateNewWatchlist = true }) {
43 Image(systemName: "plus") 46 Image(systemName: "plus")
44 } 47 }
45 } 48 }
46 } 49 }
50 }
51 .sheet(isPresented: $showCreateNewWatchlist) {
52 CreateNewWatchlist()
47 } 53 }
48 } else { 54 } else {
49 ProgressView() 55 ProgressView()
50 .onAppear { prepareUrl(isInitRequest: true) } 56 .onAppear { prepareUrl(isInitRequest: true) }
51 } 57 }