Mercurial > public > lazybear
comparison LazyBear/Views/Profile/ProfileView.swift @ 424:6dd97877f575
Improve code, reorganize files
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 13 Jun 2021 19:40:42 +0200 |
parents | 5f21f7c23c5e |
children | e707dbfc3115 |
comparison
equal
deleted
inserted
replaced
423:bdfdf3a1b34e | 424:6dd97877f575 |
---|---|
23 List { | 23 List { |
24 /* | 24 /* |
25 Get Watchlist names -> Create rows for each watchlist -> in each row, show companies | 25 Get Watchlist names -> Create rows for each watchlist -> in each row, show companies |
26 */ | 26 */ |
27 let watchlists = Set(watchlistCompanies.map { $0.watchlist }) /// Set -> avoid duplicates names | 27 let watchlists = Set(watchlistCompanies.map { $0.watchlist }) /// Set -> avoid duplicates names |
28 | |
28 ForEach(Array(watchlists).sorted(), id: \.self) { listName in | 29 ForEach(Array(watchlists).sorted(), id: \.self) { listName in |
29 let symbols = watchlistCompanies.filter({ $0.watchlist == listName }).map { $0.symbol } | 30 let symbols = watchlistCompanies.filter({ $0.watchlist == listName }).map { $0.symbol } /// Get symbols contained in specified watchlist (Core Data) |
31 | |
30 if let companies = profile.data.quotes { | 32 if let companies = profile.data.quotes { |
31 let list = companies.filter({ symbols.contains($0.key) }) /// From API response select the companies within the specified watchlist | 33 let list = companies.filter({ symbols.contains($0.key) }) /// From API response select the companies within the specified watchlist |
32 StockRow(listName: listName, list: list, intradayPrices: profile.data.intradayPrices, addOnDelete: true) | 34 StockRow(list: [listName: list], intradayPrices: profile.data.intradayPrices) |
33 } | 35 } |
34 } | 36 } |
35 .listRowInsets(EdgeInsets()) | 37 .listRowInsets(EdgeInsets()) |
36 .onAppear { /// Request API again when Core Data changes to update the list | 38 .onAppear { /// Request API again when Core Data changes to update the list |
37 refreshList() | 39 refreshList() |
38 } | 40 } |
39 } | 41 } |
40 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer | 42 .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } /// Start timer |
41 .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer | 43 .onDisappear { self.timer.upstream.connect().cancel() } /// Stop timer |
42 .onReceive(timer) { _ in | 44 .onReceive(timer) { _ in |
43 if !showCreateNewWatchlist { | 45 if !showCreateNewWatchlist { |
44 prepareUrl(.streaming) | 46 prepareUrl(.streaming) |
45 } | 47 } |
46 } | 48 } |