changeset 383:5d7a66e2b39f

Reorganise file
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 24 Apr 2021 00:41:18 +0200
parents dc48cf87ded9
children cada87844a96
files LazyBear/Views/Global Helpers/ExtensiveList.swift
diffstat 1 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Global Helpers/ExtensiveList.swift	Sat Apr 24 00:41:18 2021 +0200
@@ -0,0 +1,72 @@
+//
+//  ExtensiveList.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 14/4/21.
+//
+
+import SwiftUI
+
+struct ExtensiveList: View {
+    var listName: String
+    var list: [String: QuoteModel]?
+    var intradayPrices: [String: [IntradayPriceModel]]?
+    var latestCurrencies: [String: CurrencyModel]?
+    var addOnDelete: Bool
+    
+    @Environment(\.presentationMode) private var extensiveListPresent
+    @State var isEditMode: EditMode = .inactive
+    
+    var body: some View {
+        NavigationView {
+            VStack {
+                if let list = list {
+                    List {
+                        ForEach(Array(list.keys.sorted()), id: \.self) { companySymbol in
+                                StockItem(symbol: companySymbol,
+                                          company: list[companySymbol]!,
+                                          intradayPrices: intradayPrices?[companySymbol],
+                                          orientation: .horizontal,
+                                          hidePriceView: self.isEditMode == .active  // Hide on EditMode
+                                )
+                            
+                        }
+                        .onDelete(perform: addOnDelete ? removeCompany: nil)
+                    }
+                }
+                
+                if let latestCurrencies = latestCurrencies {
+                    List(Array(latestCurrencies.keys.sorted()), id: \.self) { currencySymbol in
+                        CurrencyListItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!)
+                        
+                    }
+                }
+            }
+            .navigationTitle(listName)
+            .navigationBarTitleDisplayMode(.inline)
+            .toolbar {
+                ToolbarItem(placement: .navigationBarTrailing) {
+                    Button(action: { extensiveListPresent.wrappedValue.dismiss() }) {
+                        Image(systemName: "multiply")
+                            .imageScale(.large)
+                    }
+                }
+                ToolbarItem(placement: .navigationBarLeading) {
+                    if addOnDelete {
+                        EditButton()
+                    }
+                }
+            }
+            .environment(\.editMode, self.$isEditMode)  // Always after Toolbar
+        }
+    }
+    private func removeCompany(at offsets: IndexSet) {
+        print("Hello")
+    }
+}
+
+struct ExtensiveList_Previews: PreviewProvider {
+    static var previews: some View {
+        ExtensiveList(listName: "List name", addOnDelete: false)
+    }
+}