Mercurial > public > lazybear
diff LazyBear/Views/Profile/Helpers/WatchlistSheet.swift @ 453:37c13ebda381
Improve hierarchy and minor bugs fixed
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sun, 27 Jun 2021 14:18:29 +0200 |
parents | ffbb1dbab531 |
children |
line wrap: on
line diff
--- a/LazyBear/Views/Profile/Helpers/WatchlistSheet.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Profile/Helpers/WatchlistSheet.swift Sun Jun 27 14:18:29 2021 +0200 @@ -10,9 +10,7 @@ struct WatchlistSheet: View { var listName: String var apiCompanies: [CompanyModel] - @Binding var willRenameWatchlist: Bool - - @Environment(\.presentationMode) private var watchlistSheetPresentation + @Environment(\.managedObjectContext) private var moc @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) var watchlistCompanies: FetchedResults<WatchlistCompany> @@ -20,44 +18,42 @@ @State private var showDeleteListAlert = false var body: some View { - NavigationView { - VStack { - List { - ForEach(watchlistCompanies.filter { $0.watchlistName == listName }, id: \.self) { watchlistCompany in - let apiCompany = apiCompanies.first(where: { $0.symbol == watchlistCompany.symbol }) - WatchlistSheetRow(apiCompany: apiCompany!, watchlistCompany: watchlistCompany) - } - .onDelete(perform: deleteCompany) + VStack { + List { + ForEach(watchlistCompanies.filter { $0.watchlistName == listName }, id: \.self) { watchlistCompany in + let apiCompany = apiCompanies.first(where: { $0.symbol == watchlistCompany.symbol }) + WatchlistSheetRow(apiCompany: apiCompany!, watchlistCompany: watchlistCompany) } + .onDelete(perform: deleteCompany) } - .navigationTitle(listName) - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - Button(action: { willRenameWatchlist = false; watchlistSheetPresentation.wrappedValue.dismiss()} ) { - Image(systemName: "multiply") + } + .navigationTitle(listName) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { +// Button(action: { willRenameWatchlist = false; watchlistSheetPresentation.wrappedValue.dismiss()} ) { +// Image(systemName: "multiply") +// } + } + + ToolbarItem(placement: .navigationBarTrailing) { + Menu { + Section { +// Button(action: { willRenameWatchlist = true; watchlistSheetPresentation.wrappedValue.dismiss() }) { +// Label("Rename list", systemImage: "square.and.pencil") +// } } - } - - ToolbarItem(placement: .navigationBarTrailing) { - Menu { - Section { - Button(action: { willRenameWatchlist = true; watchlistSheetPresentation.wrappedValue.dismiss() }) { - Label("Rename list", systemImage: "square.and.pencil") - } - } - - if Set(watchlistCompanies.map { $0.watchlistName }).count > 1 { /// If there are only 1 watchlist (default) -> It cannot be deleted - Section(header: Text("Secondary actions")) { - Button(action: { showDeleteListAlert = true }) { - Label("Delete list", systemImage: "trash") - } + + if Set(watchlistCompanies.map { $0.watchlistName }).count > 1 { /// If there are only 1 watchlist (default) -> It cannot be deleted + Section(header: Text("Secondary actions")) { + Button(action: { showDeleteListAlert = true }) { + Label("Delete list", systemImage: "trash") } } } - label: { - Label("Options", systemImage: "ellipsis.circle") - .imageScale(.large) - } + } + label: { + Label("Options", systemImage: "ellipsis.circle") + .imageScale(.large) } } } @@ -99,7 +95,7 @@ do { try moc.save() print("List deleted") - watchlistSheetPresentation.wrappedValue.dismiss() /// Dismiss view +// watchlistSheetPresentation.wrappedValue.dismiss() /// Dismiss view } catch { print(error.localizedDescription) } @@ -110,8 +106,7 @@ static var previews: some View { WatchlistSheet( listName: "Most active", - apiCompanies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])], - willRenameWatchlist: .constant(false) + apiCompanies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])] ) } }