Mercurial > public > lazybear
comparison LazyBear/Views/Search/Helpers/SearchedCompanyItem.swift @ 393:0a4c399170c4
Implementing WatchlistCreator
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 02 May 2021 12:41:20 +0200 |
parents | 8ec37b2baafd |
children | 4c90e5b18632 |
comparison
equal
deleted
inserted
replaced
392:13f3578def61 | 393:0a4c399170c4 |
---|---|
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct SearchedCompanyItem: View { | 10 struct SearchedCompanyItem: View { |
11 var company: SearchResponse | 11 var company: SearchResponse |
12 | 12 |
13 // Only unseful when it's called from Profile View | |
14 var calledFromProfileView: Bool? | |
15 | |
16 @Environment(\.managedObjectContext) private var moc | 13 @Environment(\.managedObjectContext) private var moc |
17 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) | 14 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) |
18 var watchlistCompany: FetchedResults<WatchlistCompany> | 15 var watchlistCompany: FetchedResults<WatchlistCompany> |
19 | 16 |
20 @State private var showingActionSheet = false | 17 @State private var showingActionSheet = false |
21 | 18 |
22 var body: some View { | 19 var body: some View { |
23 let watchlistSymbols = watchlistCompany.map { $0.symbol } | 20 let watchlistSymbols = watchlistCompany.map { $0.symbol } |
24 HStack { | 21 HStack { |
25 if !(calledFromProfileView ?? false) { | 22 Button(action: { self.showingActionSheet = true }) { |
26 Button(action: { self.showingActionSheet = true }) { | 23 if watchlistSymbols.contains(company.symbol!) { |
27 if watchlistSymbols.contains(company.symbol!) { | 24 Image(systemName: "star.fill") |
28 Image(systemName: "star.fill") | 25 .foregroundColor(.yellow) |
29 .foregroundColor(.yellow) | 26 .imageScale(.large) |
30 .imageScale(.large) | 27 } else { |
31 } else { | 28 Image(systemName: "star") |
32 Image(systemName: "star") | 29 .foregroundColor(.yellow) |
33 .foregroundColor(.yellow) | 30 .imageScale(.large) |
34 .imageScale(.large) | |
35 } | |
36 } | 31 } |
37 .buttonStyle(PlainButtonStyle()) | |
38 } | 32 } |
33 .buttonStyle(PlainButtonStyle()) | |
39 | 34 |
40 VStack(alignment: .leading) { | 35 VStack(alignment: .leading) { |
41 Text(company.symbol!.uppercased()) | 36 Text(company.symbol!.uppercased()) |
42 .fontWeight(.semibold) | 37 .fontWeight(.semibold) |
43 | 38 |