Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- a/LazyBear/Views/Profile/ProfileView.swift Sun Jun 13 19:40:18 2021 +0200 +++ b/LazyBear/Views/Profile/ProfileView.swift Sun Jun 13 19:40:42 2021 +0200 @@ -25,11 +25,13 @@ Get Watchlist names -> Create rows for each watchlist -> in each row, show companies */ let watchlists = Set(watchlistCompanies.map { $0.watchlist }) /// Set -> avoid duplicates names + ForEach(Array(watchlists).sorted(), id: \.self) { listName in - let symbols = watchlistCompanies.filter({ $0.watchlist == listName }).map { $0.symbol } + let symbols = watchlistCompanies.filter({ $0.watchlist == listName }).map { $0.symbol } /// Get symbols contained in specified watchlist (Core Data) + if let companies = profile.data.quotes { let list = companies.filter({ symbols.contains($0.key) }) /// From API response select the companies within the specified watchlist - StockRow(listName: listName, list: list, intradayPrices: profile.data.intradayPrices, addOnDelete: true) + StockRow(list: [listName: list], intradayPrices: profile.data.intradayPrices) } } .listRowInsets(EdgeInsets()) @@ -37,8 +39,8 @@ refreshList() } } - .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer - .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer + .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } /// Start timer + .onDisappear { self.timer.upstream.connect().cancel() } /// Stop timer .onReceive(timer) { _ in if !showCreateNewWatchlist { prepareUrl(.streaming)