comparison Simoleon/Helpers/CurrencySelector.swift @ 75:b6f8661300f2

Added isLocked to CurrencyPairs
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Fri, 30 Jul 2021 15:52:27 +0100
parents 2b85d6ed433e
children 1069c33d3a42
comparison
equal deleted inserted replaced
74:bfb959bee6d7 75:b6f8661300f2
16 @State private var showingSubscriptionPaywall = false 16 @State private var showingSubscriptionPaywall = false
17 @State private var alertTitle = "" 17 @State private var alertTitle = ""
18 @State private var alertMessage = "" 18 @State private var alertMessage = ""
19 @State private var showingAlert = false 19 @State private var showingAlert = false
20 20
21 let currencyPairs: [String] = parseJson("CurrencyPairs.json") 21 var currencyPairs: [CurrencyPairModel] = parseJson("CurrencyPairs.json")
22
23 /*
24 If searched currency string is empty:
25 * Show all currencies
26 else:
27 * Show filtered list of currencies containing searched currency string
28 */
29 var searchResults: [CurrencyPairModel] {
30 if searchCurrency.isEmpty {
31 return currencyPairs.sorted { !$0.isLocked && $1.isLocked }
32 } else {
33 return currencyPairs.filter { $0.name.contains(searchCurrency.uppercased()) }
34 }
35 }
22 36
23 var body: some View { 37 var body: some View {
24 NavigationView { 38 NavigationView {
25 VStack { 39 VStack {
26 SearchBar(placeholder: "Search...", text: $searchCurrency) 40 SearchBar(placeholder: "Search...", text: $searchCurrency)
27 .padding() 41 .padding()
28 42
29 List(searchResults, id: \.self) { currencyPair in 43 List(searchResults, id: \.self) { currencyPair in
30 Button(action: { select(currencyPair) }) { 44 Button(action: { select(currencyPair.name) }) {
31 CurrencyRow(currencyPair: currencyPair) 45 CurrencyRow(currencyPairName: currencyPair.name)
46 }
32 } 47 }
33 }
34 .id(UUID()) 48 .id(UUID())
35 .listStyle(PlainListStyle()) 49 .listStyle(PlainListStyle())
36 .gesture(DragGesture() 50 .gesture(DragGesture()
37 .onChanged({ _ in 51 .onChanged({ _ in
38 UIApplication.shared.dismissKeyboard() 52 UIApplication.shared.dismissKeyboard()
39 }) 53 })
40 ) 54 )
41 }
42 .sheet(isPresented: $showingSubscriptionPaywall) {
43 SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall)
44 } 55 }
45 .navigationTitle("Currencies") 56 .navigationTitle("Currencies")
46 .navigationBarTitleDisplayMode(.inline) 57 .navigationBarTitleDisplayMode(.inline)
47 .toolbar { 58 .toolbar {
48 ToolbarItem(placement: .cancellationAction) { 59 ToolbarItem(placement: .cancellationAction) {
53 } 64 }
54 } 65 }
55 .alert(isPresented: $showingAlert) { 66 .alert(isPresented: $showingAlert) {
56 Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) 67 Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok")))
57 } 68 }
58 } 69 .sheet(isPresented: $showingSubscriptionPaywall) {
59 70 SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall)
60 /*
61 If searched currency string is empty:
62 * Show all currencies
63 else:
64 * Show filtered list of currencies containing searched currency string
65 */
66 var searchResults: [String] {
67 if searchCurrency.isEmpty {
68 return currencyPairs
69 } else {
70 return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) }
71 } 71 }
72 } 72 }
73 73
74 /* 74 /*
75 If user is subscribed: 75 If user is subscribed: