# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1612807733 -3600 # Node ID d3468ac3ecc69b75c5586b2b28a226c14a7c7372 # Parent 2f579fa8fd1970a13648fc43393c4b1ba62f2bcd Add Placeholders when lists are empty diff -r 2f579fa8fd19 -r d3468ac3ecc6 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Mon Feb 08 18:20:07 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Mon Feb 08 19:08:53 2021 +0100 @@ -36,7 +36,8 @@ 95B3552F25CD629F00BCDE8E /* TransactionCodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B3552E25CD629F00BCDE8E /* TransactionCodes.swift */; }; 95B395A525BDF42E009A7EB0 /* companies.json in Resources */ = {isa = PBXBuildFile; fileRef = 95B395A425BDF42E009A7EB0 /* companies.json */; }; 95D1BF4925ADCF7700E5D063 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D1BF4825ADCF7700E5D063 /* Persistence.swift */; }; - 95DDC7AB25D1A98A002B2C9A /* TitleMod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DDC7AA25D1A98A002B2C9A /* TitleMod.swift */; }; + 95DDC7B025D1ABF5002B2C9A /* Title.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DDC7AF25D1ABF5002B2C9A /* Title.swift */; }; + 95DDC7B525D1AD3C002B2C9A /* Placeholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DDC7B425D1AD3C002B2C9A /* Placeholder.swift */; }; 95E07B6B25CE9398001718AB /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E07B6A25CE9398001718AB /* AppView.swift */; }; 95E07B6E25CE95A1001718AB /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E07B6D25CE95A1001718AB /* Search.swift */; }; 95E07B7225CE95D9001718AB /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E07B7125CE95D9001718AB /* Settings.swift */; }; @@ -96,7 +97,8 @@ 95B3552E25CD629F00BCDE8E /* TransactionCodes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TransactionCodes.swift; path = lazybear/Data/TransactionCodes.swift; sourceTree = SOURCE_ROOT; }; 95B395A425BDF42E009A7EB0 /* companies.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = companies.json; path = lazybear/Data/companies.json; sourceTree = SOURCE_ROOT; }; 95D1BF4825ADCF7700E5D063 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Persistence.swift; path = LazyBear/Persistence.swift; sourceTree = SOURCE_ROOT; }; - 95DDC7AA25D1A98A002B2C9A /* TitleMod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TitleMod.swift; path = lazybear/Views/TitleMod.swift; sourceTree = SOURCE_ROOT; }; + 95DDC7AF25D1ABF5002B2C9A /* Title.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Title.swift; path = lazybear/Views/Title.swift; sourceTree = SOURCE_ROOT; }; + 95DDC7B425D1AD3C002B2C9A /* Placeholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Placeholder.swift; path = lazybear/Views/Placeholder.swift; sourceTree = SOURCE_ROOT; }; 95E07B6A25CE9398001718AB /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppView.swift; path = lazybear/AppView.swift; sourceTree = SOURCE_ROOT; }; 95E07B6D25CE95A1001718AB /* Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Search.swift; path = LazyBear/Views/Search.swift; sourceTree = SOURCE_ROOT; }; 95E07B7125CE95D9001718AB /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Settings.swift; path = LazyBear/Views/Settings.swift; sourceTree = SOURCE_ROOT; }; @@ -173,6 +175,7 @@ 95612C4F2598D48200F7698F /* SearchBar.swift */, 95ED8CD325D0242200B6B605 /* CompanyList.swift */, 95ED8CD625D0242900B6B605 /* HistoryList.swift */, + 95DDC7B425D1AD3C002B2C9A /* Placeholder.swift */, 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */, 95E411A625BEE03000A9C23F /* Watchlist.swift */, 95E411BD25BEEA6C00A9C23F /* WatchlistRow.swift */, @@ -184,7 +187,7 @@ 9598CFE225D06A6C00FA9E1B /* CreateButton.swift */, 95F6CA0425CF2A4E0064E4E9 /* ViewSelector.swift */, 95E411B525BEE84E00A9C23F /* Stock.swift */, - 95DDC7AA25D1A98A002B2C9A /* TitleMod.swift */, + 95DDC7AF25D1ABF5002B2C9A /* Title.swift */, 95F6C30825BAF7C2003CF389 /* Selection.swift */, 9520F0B125C712D000692610 /* LineChartShape.swift */, 9520F0B425C7131300692610 /* LineChart.swift */, @@ -359,7 +362,7 @@ 9520F0B525C7131300692610 /* LineChart.swift in Sources */, 9597CE0425C1DFE7004DDFED /* LogoPlaceholder.swift in Sources */, 959D28DF25CC9A1A0029F689 /* News.swift in Sources */, - 95DDC7AB25D1A98A002B2C9A /* TitleMod.swift in Sources */, + 95DDC7B025D1ABF5002B2C9A /* Title.swift in Sources */, 95E07B9D25CEAC46001718AB /* TransactionDetail.swift in Sources */, 95FE646B25C30B880052832E /* ApiModel.swift in Sources */, 95B3552F25CD629F00BCDE8E /* TransactionCodes.swift in Sources */, @@ -382,6 +385,7 @@ 95ED176B25CEFE1B00AE34B3 /* RecentSearch+CoreDataClass.swift in Sources */, 95AB4A7D259DCC0C0064C9C1 /* CompanyModel.swift in Sources */, 95E411B625BEE84E00A9C23F /* Stock.swift in Sources */, + 95DDC7B525D1AD3C002B2C9A /* Placeholder.swift in Sources */, 95ED8CD425D0242200B6B605 /* CompanyList.swift in Sources */, 95ED8CDB25D02DF300B6B605 /* LogoModifier.swift in Sources */, 9520F0B225C712D000692610 /* LineChartShape.swift in Sources */, diff -r 2f579fa8fd19 -r d3468ac3ecc6 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/CompanyList.swift --- a/lazybear/Views/CompanyList.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/CompanyList.swift Mon Feb 08 19:08:53 2021 +0100 @@ -11,11 +11,12 @@ @State var searchedCompany: String var body: some View { - ForEach(companiesData.filter({ searchedCompany.isEmpty ? true : $0.name.localizedStandardContains(searchedCompany) }) - , id: \.symbol) { company in - CompanyRow(company: company) - - } + List { + ForEach(companiesData.filter({ searchedCompany.isEmpty ? true : $0.name.localizedStandardContains(searchedCompany) }) + , id: \.symbol) { company in + CompanyRow(company: company) + } + } .id(UUID()) // Increase speed in search the list } } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/HistoryList.swift --- a/lazybear/Views/HistoryList.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/HistoryList.swift Mon Feb 08 19:08:53 2021 +0100 @@ -18,19 +18,24 @@ var body: some View { if history.count > 0 { - Section(header: Text("History"), - footer: Button(action: { self.showingActionSheet = true } - ) { - Text("Clear history").foregroundColor(.blue) - .actionSheet(isPresented: $showingActionSheet) { alert() } + List { + Section(header: Text("History"), + footer: Button(action: { self.showingActionSheet = true } + ) { + Text("Clear history").foregroundColor(.blue) + .actionSheet(isPresented: $showingActionSheet) { alert() } + } + ) { + // Sorte array by Date. The new ones come first in the list + let sorted = history.sorted { $0.date ?? Date() > $1.date ?? Date() } + ForEach(sorted) { company in + CompanyRow(history: company) } - ) { - // Sorte array by Date. The new ones come first in the list - let sorted = history.sorted { $0.date ?? Date() > $1.date ?? Date() } - ForEach(sorted) { company in - CompanyRow(history: company) } } + } else { + Placeholder(title: "Try to search something!", text: "For example, type 'Apple' in the search bar") + Spacer() } } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Placeholder.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Views/Placeholder.swift Mon Feb 08 19:08:53 2021 +0100 @@ -0,0 +1,28 @@ +// +// HistoryPlaceholder.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 8/2/21. +// + +import SwiftUI + +struct Placeholder: View { + @State var title: String + @State var text: String? + + var body: some View { + VStack(alignment: .center) { + Text(title) + Text(text ?? "") + } + .font(.body) + .opacity(0.5) + } +} + +struct HistoryPlaceholder_Previews: PreviewProvider { + static var previews: some View { + Placeholder(title: "Try to search something!", text: "For example, type 'Apple' in the search bar") + } +} diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Search.swift --- a/lazybear/Views/Search.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/Search.swift Mon Feb 08 19:08:53 2021 +0100 @@ -14,17 +14,17 @@ NavigationView { VStack { SearchBar(searchedText: $searchedCompany) - List { + Spacer() + if searchedCompany.count > 2 { CompanyList(searchedCompany: searchedCompany) } else { HistoryList() } - } - .id(UUID()) // Increase speed in search the list - .navigationBarTitle("Search", displayMode: .inline) } - } .navigationViewStyle(StackNavigationViewStyle()) + .navigationBarTitle("Search", displayMode: .inline) + } + .navigationViewStyle(StackNavigationViewStyle()) } } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Stock.swift --- a/lazybear/Views/Stock.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/Stock.swift Mon Feb 08 19:08:53 2021 +0100 @@ -30,28 +30,32 @@ VStack(alignment: .leading) { Text("Stock") .fontWeight(.semibold) - .modifier(TitleMod()) + .modifier(Title()) Divider() HStack { Price(symbol: symbol, showHorizontal: true) + .padding(.leading) + Spacer() } Divider() - Selection(items: periods, selected: $selectedPeriod) - .onChange(of: selectedPeriod, perform: { (value) in - getUrl(range: periods[selectedPeriod]) - }) - - let prices = data.map { $0.close ?? 0 } - if showingLineChart { - let normalPrices = normalize(prices) - LineChart(dataPoints: normalPrices, lineColor: colorLineChart(prices: prices) ? .green : .red, lineWidth: 2) - .frame(height: lineChartHeight) + Group { + Selection(items: periods, selected: $selectedPeriod) + .onChange(of: selectedPeriod, perform: { (value) in + getUrl(range: periods[selectedPeriod]) + }) + + let prices = data.map { $0.close ?? 0 } + if showingLineChart { + let normalPrices = normalize(prices) + LineChart(dataPoints: normalPrices, lineColor: colorLineChart(prices: prices) ? .green : .red, lineWidth: 2) + .frame(height: lineChartHeight) + } } + .padding([.leading, .trailing]) } - .padding([.leading, .trailing]) .onAppear { getUrl(range: periods[selectedPeriod]) } } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Title.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Views/Title.swift Mon Feb 08 19:08:53 2021 +0100 @@ -0,0 +1,16 @@ +// +// TitleMod.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 8/2/21. +// + +import SwiftUI + +struct Title: ViewModifier { + func body(content: Content) -> some View { + content + .font(.title) + .padding([.leading, .top]) + } +} diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/TitleMod.swift --- a/lazybear/Views/TitleMod.swift Mon Feb 08 18:20:07 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -// -// TitleMod.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 8/2/21. -// - -import SwiftUI - -struct TitleMod: ViewModifier { - func body(content: Content) -> some View { - content - .font(.title) - .padding([.leading, .top, .bottom]) - } -} diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/TransactionDetail.swift --- a/lazybear/Views/TransactionDetail.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/TransactionDetail.swift Mon Feb 08 19:08:53 2021 +0100 @@ -54,11 +54,11 @@ } let price = data.transactionPrice ?? 0 if price != 0 { - Text("Price per share: $\(shares, specifier: "%.2f")") + Text("Price per share: $\(price, specifier: "%.2f")") } let value = data.transactionValue ?? 0 if value != 0 { - Text("Transaction value: $\(shares, specifier: "%.2f")") + Text("Transaction value: $\(value, specifier: "%.2f")") } } } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Transactions.swift --- a/lazybear/Views/Transactions.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/Transactions.swift Mon Feb 08 19:08:53 2021 +0100 @@ -20,13 +20,15 @@ var body: some View { VStack(alignment: .leading) { - Text("Insider transactions") + Text("Insiders") .fontWeight(.semibold) - .modifier(TitleMod()) + .modifier(Title()) List { - ForEach(data, id: \.self) { data in - TransactionRow(data: data) + Section(header: Text("Transactions")) { + ForEach(data, id: \.self) { data in + TransactionRow(data: data) + } } } } .onAppear { getUrl() } diff -r 2f579fa8fd19 -r d3468ac3ecc6 lazybear/Views/Watchlist.swift --- a/lazybear/Views/Watchlist.swift Mon Feb 08 18:20:07 2021 +0100 +++ b/lazybear/Views/Watchlist.swift Mon Feb 08 19:08:53 2021 +0100 @@ -15,19 +15,26 @@ var body: some View { NavigationView { - List { - Section(header: Text("Watchlist")) { - ForEach(companies) { company in - WatchlistRow(company: company) + VStack { + if companies.count > 0 { + List { + Section(header: Text("Watchlist")) { + ForEach(companies) { company in + WatchlistRow(company: company) + } + .onDelete { indexSet in deleteWatchlist(indexSet: indexSet) } // Delete from persistent storage + } } - .onDelete { indexSet in deleteWatchlist(indexSet: indexSet) } // Delete from persistent storage + .toolbar { EditButton() } + } else { + Placeholder(title: "Seems that your watchlist is empty!", text: "Search and add a company.") } } .navigationBarTitle("Watchlist", displayMode: .inline) - .toolbar { EditButton() } - - }.navigationViewStyle(StackNavigationViewStyle()) + } + .navigationViewStyle(StackNavigationViewStyle()) } + func deleteWatchlist(indexSet: IndexSet) { for index in indexSet {