comparison LazyBear/Views/Profile/Helpers/ProfileStockRow.swift @ 432:3ca32ff79630

Fixes RenameSheetList bug
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 19 Jun 2021 20:13:25 +0200
parents
children 37c13ebda381
comparison
equal deleted inserted replaced
431:871c10220a3d 432:3ca32ff79630
1 //
2 // ProfileStockRow.swift
3 // LazyBear
4 //
5 // Created by Dennis Concepción Martín on 19/6/21.
6 //
7
8 import SwiftUI
9
10 struct ProfileStockRow: View {
11 var watchlistName: String
12 var companies: [CompanyModel]
13
14 @State private var showWatchlistSheet = false
15 @State private var willRenameWatchlist = false
16 @State private var showRenameWatchlistSheet = false
17 @Environment(\.managedObjectContext) private var moc
18
19 var body: some View {
20 VStack(alignment: .leading) {
21 HStack(alignment: .bottom) {
22 VStack(alignment: .leading) {
23 Text(watchlistName)
24 .font(.title3)
25 .fontWeight(.semibold)
26 .padding([.top, .horizontal])
27
28 Text("Real-time quotes")
29 .font(.caption)
30 .opacity(0.5)
31 .padding(.horizontal)
32 }
33
34 Spacer()
35 Button("See all", action: { showWatchlistSheet = true })
36 .buttonStyle(BorderlessButtonStyle())
37 .padding(.horizontal)
38 }
39
40 ScrollView(.horizontal, showsIndicators: false) {
41 HStack(spacing: 20) {
42 ForEach(companies, id: \.self) { company in
43 StockItem(company: company)
44 }
45 }
46 .padding()
47 }
48 .frame(height: 250)
49 }
50 .padding(.bottom)
51 .sheet(isPresented: $showWatchlistSheet, onDismiss: didDismissWatchlistSheet) {
52 WatchlistSheet(listName: watchlistName, apiCompanies: companies, willRenameWatchlist: $willRenameWatchlist)
53 .environment(\.managedObjectContext, self.moc)
54 }
55 .sheet(isPresented: $showRenameWatchlistSheet) {
56 RenameListSheet(oldWatchlistName: watchlistName)
57 .environment(\.managedObjectContext, self.moc)
58 }
59 }
60
61 /*
62 If user wants to rename watchlist -> when WatchlistSheet is dismissed, show RenameListSheet
63 */
64 private func didDismissWatchlistSheet() {
65 if willRenameWatchlist {
66 showRenameWatchlistSheet = true
67 }
68 }
69 }
70
71 struct ProfileStockRow_Previews: PreviewProvider {
72 static var previews: some View {
73 ProfileStockRow(
74 watchlistName: "mostactive",
75 companies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])]
76 )
77 }
78 }