Mercurial > public > simoleon
diff Simoleon/UI/CurrencyList.swift @ 161:3913aff613e8
Fix bug that didn't request API on symbol change
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Tue, 31 Aug 2021 10:57:34 +0100 |
parents | 0c589138a6f3 |
children | 1940db1ef321 |
line wrap: on
line diff
--- a/Simoleon/UI/CurrencyList.swift Sun Aug 29 19:04:34 2021 +0100 +++ b/Simoleon/UI/CurrencyList.swift Tue Aug 31 10:57:34 2021 +0100 @@ -9,8 +9,10 @@ struct CurrencyList: View { var currencies: [String] - @Binding var selectedCurrency: String + var selection: Selection + @ObservedObject var currencyConversion: CurrencyConversion @State private var searchCurrency = "" + @Environment(\.presentationMode) private var presentation let currencyDetails: [String: CurrencyModel] = try! readJson(from: "Currencies.json") @@ -30,7 +32,15 @@ .accessibilityIdentifier("CurrencySearchBar") ForEach(searchResults, id: \.self) { symbol in - Button(action: {selectedCurrency = symbol; presentation.wrappedValue.dismiss()}) { + Button(action: { + if selection == .baseSymbol { + currencyConversion.baseSymbol = symbol + } else { + currencyConversion.quoteSymbol = symbol + } + + presentation.wrappedValue.dismiss() + }) { let currency = currencyDetails[symbol]! CurrencyRow(currency: currency) } @@ -48,6 +58,10 @@ } } } + + enum Selection { + case baseSymbol, quoteSymbol + } } extension View { func listStyle() -> some View { @@ -57,6 +71,6 @@ struct CurrencyList_Previews: PreviewProvider { static var previews: some View { - CurrencyList(currencies: ["USD"], selectedCurrency: .constant("USD")) + CurrencyList(currencies: ["USD"], selection: .baseSymbol, currencyConversion: CurrencyConversion()) } }