view LazyBear/Views/Global Helpers/StockRow.swift @ 375:f3cb5bdea8e5

Update Codable requests in HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 21 Apr 2021 16:19:50 +0200
parents eb97439e46cd
children a7e2c5a7b4f6
line wrap: on
line source

//
//  StockRow.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 28/3/21.
//

import SwiftUI


struct StockRow: View {
    var listName: String
    var list: [String: QuoteModel]
    var intradayPrices: [String: [IntradayPriceModel]]?
    
    @State private var showExtensiveList = false
    
    var body: some View {
        VStack(alignment: .leading) {
            HStack(alignment: .bottom) {
                VStack(alignment: .leading) {
                    Text(listName)
                        .font(.title3)
                        .fontWeight(.semibold)
                        .padding([.top, .horizontal])
                    
                    Text("Real-time quotes")
                        .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(list.keys.sorted()), id: \.self) { companySymbol in
                        StockItem(symbol: companySymbol, company: list[companySymbol]!, intradayPrices: intradayPrices?[companySymbol], orientation: .vertical)
                    }
                }
                .padding()
            }
            .frame(height: 250)
        }
        .padding(.bottom)
        .sheet(isPresented: $showExtensiveList) {
            ExtensiveList(listName: listName, list: list, intradayPrices: intradayPrices, latestCurrencies: nil)
        }
    }
}


struct StockRectangleRow_Previews: PreviewProvider {
    static var previews: some View {
        StockRow(
            listName: "Gainers",
            list: ["AAPL": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 130.3)],
            intradayPrices: ["AAPL": [IntradayPriceModel(open: 130.2)]]
        )
    }
}