Mercurial > public > lazybear
comparison LazyBear/Views/Search/SearchView.swift @ 358:280cbc5653b5
SearchView implemented
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 16 Apr 2021 17:03:48 +0200 |
parents | 80bfa88c6b0f |
children | 8162ccc5ec5c |
comparison
equal
deleted
inserted
replaced
357:eb97439e46cd | 358:280cbc5653b5 |
---|---|
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 search = Search() |
13 // @State private var searchedText: String = "" | 13 @State private var searchedText = String() |
14 // @State private var showingSearchList = false | 14 @EnvironmentObject var hudManager: HudManager |
15 // @EnvironmentObject var hudManager: HudManager | 15 |
16 // | 16 var body: some View { |
17 // var body: some View { | 17 NavigationView { |
18 // NavigationView { | 18 VStack(alignment: .leading) { |
19 // VStack(alignment: .leading) { | 19 if search.showSearchList { |
20 // if showingSearchList { | 20 CompanyList(searchResult: search.data) |
21 // CompanyList(searchResult: searchData.searchResult) | 21 } else { |
22 // } else { | 22 VStack(alignment: .center) { |
23 // VStack(alignment: .center) { | 23 Image("bearSleeping") |
24 // Image("bearSleeping") | 24 .resizable() |
25 // .resizable() | 25 .scaledToFit() |
26 // .scaledToFit() | 26 |
27 // | 27 Text("Are you looking for something?") |
28 // Text("Are you looking for something?") | 28 .font(.title2) |
29 // .font(.title2) | 29 .fontWeight(.semibold) |
30 // .fontWeight(.semibold) | 30 .multilineTextAlignment(.center) |
31 // .multilineTextAlignment(.center) | 31 .padding(.bottom) |
32 // .padding(.bottom) | 32 |
33 // | 33 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!") | 34 .multilineTextAlignment(.center) |
35 // .multilineTextAlignment(.center) | 35 } |
36 // } | 36 .padding(.horizontal) |
37 // .padding(.horizontal) | 37 } |
38 // } | 38 } |
39 // } | 39 .navigationTitle("Search") |
40 // .onDisappear { self.searchedText = ""; self.showingSearchList = false } | 40 .navigationBarTitleDisplayMode(.inline) |
41 // .navigationTitle("Search") | 41 .navigationBarSearch($searchedText) |
42 // .navigationBarTitleDisplayMode(.inline) | 42 .onChange(of: searchedText, perform: { searchedText in |
43 // .navigationBarSearch($searchedText) | 43 if !searchedText.isEmpty { |
44 // .onChange(of: searchedText, perform: { searchedText in | 44 // Encode string with spaces |
45 // showSearchList(searchedText) | 45 let encodedSearchedText = searchedText.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) |
46 // }) | 46 search.request("https://api.lazybear.app/search/\(encodedSearchedText ?? "")") |
47 // .toolbar { | 47 } else { |
48 // ToolbarItem(placement: .navigationBarTrailing) { | 48 search.showSearchList = false |
49 // Button(action: { self.hudManager.showSearchHelper = true }) { | 49 } |
50 // Image(systemName: "questionmark.circle") | 50 }) |
51 // } | 51 .toolbar { |
52 // } | 52 ToolbarItem(placement: .navigationBarTrailing) { |
53 // } | 53 Button(action: { self.hudManager.showSearchHelper = true }) { |
54 // } | 54 Image(systemName: "questionmark.circle") |
55 // } | 55 } |
56 // | 56 } |
57 // private func showSearchList(_ searchedText: String) { | 57 } |
58 // if !searchedText.isEmpty { | 58 } |
59 // // Encode string with spaces | 59 } |
60 // let encodedSearchedText = searchedText.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) | 60 } |
61 // searchData.get(encodedSearchedText!) | 61 |
62 // self.showingSearchList = true | 62 struct SearchView_Previews: PreviewProvider { |
63 // } | 63 static var previews: some View { |
64 // } | 64 SearchView() |
65 //} | 65 } |
66 // | 66 } |
67 //struct SearchView_Previews: PreviewProvider { | |
68 // static var previews: some View { | |
69 // SearchView() | |
70 // } | |
71 //} |