comparison LazyBear/Views/Search/SearchView.swift @ 346:80bfa88c6b0f

Implementing Prop API
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 11 Apr 2021 19:55:47 +0200
parents 276e17f11c19
children 280cbc5653b5
comparison
equal deleted inserted replaced
345:fde2b30c719e 346:80bfa88c6b0f
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 import SwiftlySearch 9 import SwiftlySearch
10 10
11 struct SearchView: View { 11 //struct SearchView: View {
12 @ObservedObject var searchData = SearchData() 12 // @ObservedObject var searchData = SearchData()
13 @State private var searchedText: String = "" 13 // @State private var searchedText: String = ""
14 @State private var showingSearchList = false 14 // @State private var showingSearchList = false
15 @EnvironmentObject var hudManager: HudManager 15 // @EnvironmentObject var hudManager: HudManager
16 16 //
17 var body: some View { 17 // var body: some View {
18 NavigationView { 18 // NavigationView {
19 VStack(alignment: .leading) { 19 // VStack(alignment: .leading) {
20 if showingSearchList { 20 // if showingSearchList {
21 CompanyList(searchResult: searchData.searchResult) 21 // CompanyList(searchResult: searchData.searchResult)
22 } else { 22 // } else {
23 VStack(alignment: .center) { 23 // VStack(alignment: .center) {
24 Image("bearSleeping") 24 // Image("bearSleeping")
25 .resizable() 25 // .resizable()
26 .scaledToFit() 26 // .scaledToFit()
27 27 //
28 Text("Are you looking for something?") 28 // Text("Are you looking for something?")
29 .font(.title2) 29 // .font(.title2)
30 .fontWeight(.semibold) 30 // .fontWeight(.semibold)
31 .multilineTextAlignment(.center) 31 // .multilineTextAlignment(.center)
32 .padding(.bottom) 32 // .padding(.bottom)
33 33 //
34 Text("Use the search bar to find your favourite company. Type the stock symbol or name, we'll find it!") 34 // Text("Use the search bar to find your favourite company. Type the stock symbol or name, we'll find it!")
35 .multilineTextAlignment(.center) 35 // .multilineTextAlignment(.center)
36 } 36 // }
37 .padding(.horizontal) 37 // .padding(.horizontal)
38 } 38 // }
39 } 39 // }
40 .onDisappear { self.searchedText = ""; self.showingSearchList = false } 40 // .onDisappear { self.searchedText = ""; self.showingSearchList = false }
41 .navigationTitle("Search") 41 // .navigationTitle("Search")
42 .navigationBarTitleDisplayMode(.inline) 42 // .navigationBarTitleDisplayMode(.inline)
43 .navigationBarSearch($searchedText) 43 // .navigationBarSearch($searchedText)
44 .onChange(of: searchedText, perform: { searchedText in 44 // .onChange(of: searchedText, perform: { searchedText in
45 showSearchList(searchedText) 45 // showSearchList(searchedText)
46 }) 46 // })
47 .toolbar { 47 // .toolbar {
48 ToolbarItem(placement: .navigationBarTrailing) { 48 // ToolbarItem(placement: .navigationBarTrailing) {
49 Button(action: { self.hudManager.showSearchHelper = true }) { 49 // Button(action: { self.hudManager.showSearchHelper = true }) {
50 Image(systemName: "questionmark.circle") 50 // Image(systemName: "questionmark.circle")
51 } 51 // }
52 } 52 // }
53 } 53 // }
54 } 54 // }
55 } 55 // }
56 56 //
57 private func showSearchList(_ searchedText: String) { 57 // private func showSearchList(_ searchedText: String) {
58 if !searchedText.isEmpty { 58 // if !searchedText.isEmpty {
59 // Encode string with spaces 59 // // Encode string with spaces
60 let encodedSearchedText = searchedText.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) 60 // let encodedSearchedText = searchedText.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
61 searchData.get(encodedSearchedText!) 61 // searchData.get(encodedSearchedText!)
62 self.showingSearchList = true 62 // self.showingSearchList = true
63 } 63 // }
64 } 64 // }
65 } 65 //}
66 66 //
67 struct SearchView_Previews: PreviewProvider { 67 //struct SearchView_Previews: PreviewProvider {
68 static var previews: some View { 68 // static var previews: some View {
69 SearchView() 69 // SearchView()
70 } 70 // }
71 } 71 //}