# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1613925482 -3600 # Node ID 235ee168a9c36a2d8f92e6f9c92ac711a49222aa # Parent 8ed956c01a540d9a81fb90e3049fb4b2df651711 Fix URL encoding bug clean company search list diff -r 8ed956c01a54 -r 235ee168a9c3 LazyBear/Functions/Normalize.swift --- /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() + } +} diff -r 8ed956c01a54 -r 235ee168a9c3 LazyBear/HUDManager.swift --- /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() + } +} diff -r 8ed956c01a54 -r 235ee168a9c3 LazyBear/Tests/ChartTests.swift --- /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() + } +} diff -r 8ed956c01a54 -r 235ee168a9c3 LazyBear/UI/HUD.swift --- /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) + } +} diff -r 8ed956c01a54 -r 235ee168a9c3 LazyBear/UI/Search.swift --- 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()) } }