view LazyBear/Views/Home/Helpers/CurrencyRow.swift @ 379:a7e2c5a7b4f6

Implement onDelete in watchlists
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 22 Apr 2021 23:44:20 +0200
parents f3cb5bdea8e5
children a0cf8fe47044
line wrap: on
line source

//
//  CurrencyRow.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 14/4/21.
//

import SwiftUI

struct CurrencyRow: View {
    var latestCurrencies: [String: CurrencyModel]
    
    @State private var showExtensiveList = false
    
    var body: some View {
        VStack(alignment: .leading) {
            HStack(alignment: .bottom) {
                VStack(alignment: .leading) {
                    Text("Currencies")
                        .font(.title3)
                        .fontWeight(.semibold)
                        .padding([.top, .horizontal])
                    
                    Text("Updated at 6:00 CET on every working day")
                        .font(.caption)
                        .opacity(0.5)
                        .padding(.horizontal)
                }
                
                Spacer()
                Button("See all", action: { self.showExtensiveList = true })
                    .buttonStyle(BorderlessButtonStyle())
                    .padding(.horizontal)
            }
            
            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 20) {
                    ForEach(Array(latestCurrencies.keys), id: \.self) { currencySymbol in
                        CurrencyItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!)
                    }
                }
                .padding()
            }
        }
        .sheet(isPresented: $showExtensiveList) {
            ExtensiveList(listName: "Currencies", latestCurrencies: latestCurrencies, addOnDelete: false)
        }
    }
}

struct CurrencyRow_Previews: PreviewProvider {
    static var previews: some View {
        CurrencyRow(latestCurrencies: ["AUD": CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)])
    }
}