Mercurial > public > lazybear
changeset 177:235ee168a9c3
Fix URL encoding bug
clean company search list
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 21 Feb 2021 17:38:02 +0100 |
parents | 8ed956c01a54 |
children | c1aa75608c27 |
files | LazyBear/Functions/Normalize.swift LazyBear/HUDManager.swift LazyBear/Tests/ChartTests.swift LazyBear/UI/HUD.swift LazyBear/UI/Search.swift |
diffstat | 5 files changed, 112 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Functions/Normalize.swift Sun Feb 21 17:38:02 2021 +0100 @@ -0,0 +1,20 @@ +// +// Normalize.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 20/2/21. +// + +import SwiftUI + +struct Normalize: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct Normalize_Previews: PreviewProvider { + static var previews: some View { + Normalize() + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/HUDManager.swift Sun Feb 21 17:38:02 2021 +0100 @@ -0,0 +1,20 @@ +// +// HUDManager.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 21/2/21. +// + +import SwiftUI + +struct HUDManager: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct HUDManager_Previews: PreviewProvider { + static var previews: some View { + HUDManager() + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Tests/ChartTests.swift Sun Feb 21 17:38:02 2021 +0100 @@ -0,0 +1,20 @@ +// +// ChartTests.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 20/2/21. +// + +import SwiftUI + +struct ChartTests: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct ChartTests_Previews: PreviewProvider { + static var previews: some View { + ChartTests() + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/UI/HUD.swift Sun Feb 21 17:38:02 2021 +0100 @@ -0,0 +1,34 @@ +// +// HUD.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 21/2/21. +// + +import SwiftUI + +struct HUD: View { + @ViewBuilder var body: some View { + Text("Saved image") + .foregroundColor(.gray) + .padding(.horizontal, 10) + .padding(14) + .background( + Blur(style: .systemMaterial) + .clipShape(Capsule()) + .shadow(color: Color(.black).opacity(0.22), radius: 12, x: 0, y: 5) + ) + } +} + +struct Blur: UIViewRepresentable { + var style: UIBlurEffect.Style + + func makeUIView(context: Context) -> UIVisualEffectView { + return UIVisualEffectView(effect: UIBlurEffect(style: style)) + } + + func updateUIView(_ uiView: UIVisualEffectView, context: Context) { + uiView.effect = UIBlurEffect(style: style) + } +}
--- a/LazyBear/UI/Search.swift Sat Feb 20 19:29:31 2021 +0100 +++ b/LazyBear/UI/Search.swift Sun Feb 21 17:38:02 2021 +0100 @@ -9,13 +9,14 @@ import SwiftlySearch struct Search: View { + @ObservedObject var hudManager: HUDManager @State private var company = String() @State private var companies = [CompanyModel]() var body: some View { NavigationView { - List(companies, id: \.symbol) { company in - NavigationLink(destination: CompanyView(name: company.securityName ?? "-", symbol: company.symbol) + List(filterList(), id: \.symbol) { company in + NavigationLink(destination: CompanyView(hudManager: hudManager, name: company.securityName ?? "-", symbol: company.symbol) .navigationTitle(company.symbol) ) { CompanyRow(symbol: company.symbol, name: company.securityName ?? "-") @@ -34,14 +35,27 @@ private func getUrl() -> String { let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url" let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key" - let url = "\(baseUrl)/search/\(company)?token=\(apiKey)" + let encodedCompanyName = company.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) + let url = "\(baseUrl)/search/\(encodedCompanyName!)?token=\(apiKey)" return url } + + private func filterList() -> [CompanyModel] { + // Exclude symbols with "-" and numbers -> they are secondary stock symbols + // of the same company but different market. Currently, not interested in them. + let decimalCharacters = CharacterSet.decimalDigits + let filteredCompanies = companies.filter { + $0.symbol.rangeOfCharacter(from: decimalCharacters) == nil && // Exclude symbols with numbers + !$0.symbol.contains("-") // Exclude symbols with "-" + } + + return filteredCompanies + } } struct Search_Previews: PreviewProvider { static var previews: some View { - Search() + Search(hudManager: HUDManager()) } }