Mercurial > public > lazybear
comparison LazyBear/Views/Profile/ProfileView.swift @ 378:6802c2393203
Implementing ProfileView (Watchlists)
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 21 Apr 2021 23:12:56 +0200 |
parents | d01859776fe6 |
children | a7e2c5a7b4f6 |
comparison
equal
deleted
inserted
replaced
377:d01859776fe6 | 378:6802c2393203 |
---|---|
4 // | 4 // |
5 // Created by Dennis Concepción Martín on 4/4/21. | 5 // Created by Dennis Concepción Martín on 4/4/21. |
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 import CoreData | |
9 | 10 |
10 struct ProfileView: View { | 11 struct ProfileView: View { |
11 @ObservedObject var profile = Profile() | 12 @ObservedObject var profile = Profile() |
13 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) | |
14 var watchlistCompanies: FetchedResults<WatchlistCompany> | |
12 | 15 |
13 var body: some View { | 16 var body: some View { |
14 NavigationView { | 17 if profile.showView { |
15 List { | 18 NavigationView { |
16 | 19 List { |
20 // Take all the different watchlist created | |
21 let watchlists = Set(watchlistCompanies.map { $0.watchlist }) // Set -> avoid duplicates names | |
22 ForEach(Array(watchlists), id: \.self) { watchlist in | |
23 | |
24 // Get all the symbols of this watchlist | |
25 let symbols = watchlistCompanies.filter({ $0.watchlist == watchlist }).map { $0.symbol } | |
26 | |
27 if let companies = profile.data.quotes { | |
28 let filteredCompanies = companies.filter({ symbols.contains($0.key) }) | |
29 StockRow(listName: watchlist, list: filteredCompanies, intradayPrices: profile.data.intradayPrices) | |
30 .listRowInsets(EdgeInsets()) | |
31 } | |
32 } | |
33 } | |
34 .navigationTitle("My profile") | |
35 .navigationBarTitleDisplayMode(.inline) | |
36 } | |
37 } else { | |
38 ProgressView() | |
39 .onAppear { prepareUrl() } | |
40 } | |
41 } | |
42 | |
43 private func prepareUrl() { | |
44 let symbols = watchlistCompanies.map { $0.symbol } // Get symbols in watchlists | |
45 var url = "https://api.lazybear.app/profile/type=init/symbols=" | |
46 print(url) | |
17 | 47 |
18 } | 48 var counter = 0 |
19 .navigationTitle("My profile") | 49 for symbol in symbols { |
20 .navigationBarTitleDisplayMode(.inline) | 50 counter += 1 |
21 .onAppear { | 51 if counter == 1 { |
22 profile.request("https://api.lazybear.app/profile/type=init/symbols=aapl,fb") | 52 url += symbol |
53 } else { | |
54 url += ",\(symbol)" | |
23 } | 55 } |
24 } | 56 } |
57 profile.request(url) | |
25 } | 58 } |
26 } | 59 } |
27 | 60 |
28 struct ProfileView_Previews: PreviewProvider { | 61 struct ProfileView_Previews: PreviewProvider { |
29 static var previews: some View { | 62 static var previews: some View { |