comparison LazyBear/Views/Search/CompanyList.swift @ 392:13f3578def61

Implement create watchlist
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 01 May 2021 13:11:32 +0200
parents 8ec37b2baafd
children 0a4c399170c4
comparison
equal deleted inserted replaced
391:8ec37b2baafd 392:13f3578def61
11 var searchResult: [SearchResponse] 11 var searchResult: [SearchResponse]
12 12
13 // Only unseful when it's called from Profile View 13 // Only unseful when it's called from Profile View
14 var calledFromProfileView: Bool? 14 var calledFromProfileView: Bool?
15 var newWatchlistClass: NewWatchlistClass? 15 var newWatchlistClass: NewWatchlistClass?
16 @Binding var presentationMode: PresentationMode
16 17
17 var body: some View { 18 var body: some View {
18 List(searchResult, id: \.self) { company in 19 List(searchResult, id: \.self) { company in
19 SearchedCompanyItem(company: company, calledFromProfileView: calledFromProfileView) 20 SearchedCompanyItem(company: company, calledFromProfileView: calledFromProfileView)
20 .if(calledFromProfileView ?? false ) { content in 21 .if(calledFromProfileView ?? false ) { content in
21 Button(action: { newWatchlistClass!.companies.append(company) }) { 22 Button(action: { save(company) }) {
22 content 23 content
23 } 24 }
24 } 25 }
25 } 26 }
27 }
28
29 private func save(_ company: SearchResponse) {
30 newWatchlistClass!.companies.append(company)
31 $presentationMode.wrappedValue.dismiss() // Dismiss view
26 } 32 }
27 } 33 }
28 34
29 /* 35 /*
30 Wrap view on condition 36 Wrap view on condition
41 } 47 }
42 } 48 }
43 } 49 }
44 50
45 struct CompanyList_Previews: PreviewProvider { 51 struct CompanyList_Previews: PreviewProvider {
52 @Environment(\.presentationMode) static var presentationMode
53
46 static var previews: some View { 54 static var previews: some View {
47 CompanyList(searchResult: [SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl")]) 55 CompanyList(searchResult: [SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl")], presentationMode: presentationMode)
48 } 56 }
49 } 57 }