Mercurial > public > lazybear
changeset 412:a7c9dd0c5822
Main insider view implemented
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Tue, 08 Jun 2021 11:46:58 +0200 |
parents | 681fb377235e |
children | 2984d8946342 |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/Global Models/InsiderTransactionModel.swift LazyBear/Views/Company/Chart.swift LazyBear/Views/Company/Helpers/InsiderList.swift LazyBear/Views/Company/Helpers/TransactionList.swift LazyBear/Views/Company/Helpers/TransactionRow.swift LazyBear/Views/Company/Insiders.swift LazyBear/Views/Company/Networking/InsidersResponse.swift |
diffstat | 9 files changed, 88 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Tue Jun 08 11:46:58 2021 +0200 @@ -491,10 +491,10 @@ 95E31C15264736BE00106B98 /* DatePicker.swift */, 95613AE0264FD34100D4CE8F /* NewsRow.swift */, 950857A8266BD2C6005357BA /* SFSafariViewWrapper.swift */, + 95CCFB57266E7F4F00C384A1 /* InsiderList.swift */, 950857D0266BE54B005357BA /* InsiderRow.swift */, - 95CCFB57266E7F4F00C384A1 /* InsiderList.swift */, + 95CCFB5B266E842000C384A1 /* TransactionList.swift */, 95CCFB59266E841B00C384A1 /* TransactionRow.swift */, - 95CCFB5B266E842000C384A1 /* TransactionList.swift */, ); path = Helpers; sourceTree = "<group>";
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/Global Models/InsiderTransactionModel.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Global Models/InsiderTransactionModel.swift Tue Jun 08 11:46:58 2021 +0200 @@ -7,13 +7,13 @@ import SwiftUI -struct InsiderTransactionModel: Codable { +struct InsiderTransactionModel: Codable, Hashable { var filingDate: String var fullName: String - var postShares: Int + var postShares: Int? var reportedTitle: String? var transactionCode: String - var transactionPrice: Float - var transactionShares: Int - var transactionValue: Float + var transactionPrice: Float? + var transactionShares: Int? + var transactionValue: Float? }
--- a/LazyBear/Views/Company/Chart.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Chart.swift Tue Jun 08 11:46:58 2021 +0200 @@ -70,7 +70,7 @@ .padding(.top) } } - .onAppear { print("appeared"); self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer + .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer .onReceive(timer) { _ in let url = "https://api.lazybear.app/company/chart/symbol=\(symbol)/type=streaming"
--- a/LazyBear/Views/Company/Helpers/InsiderList.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/InsiderList.swift Tue Jun 08 11:46:58 2021 +0200 @@ -9,8 +9,6 @@ struct InsiderList: View { var insiderSummary: [InsiderRosterModel] - var numberOfRows: Int - @State private var showFullList = false var body: some View { @@ -27,7 +25,7 @@ // Get total shares owned by the top 10 insiders let totalPositions = insiderSummary.map { $0.position }.reduce(0, +) VStack(alignment: .leading, spacing: 20) { - ForEach(insiderSummary.prefix(numberOfRows), id: \.self) { insider in + ForEach(insiderSummary.prefix(3), id: \.self) { insider in // Compute percentage of ownership for each insider let percentage = Double(insider.position) / Double(totalPositions) @@ -45,8 +43,8 @@ struct InsiderList_Previews: PreviewProvider { static var previews: some View { InsiderList(insiderSummary: - [InsiderRosterModel(entityName: "Dennis Concepcion", position: 1234, reportDate: 1234567)], - numberOfRows: 3) + [InsiderRosterModel(entityName: "Dennis Concepcion", position: 1234, reportDate: 1234567)] + ) } }
--- a/LazyBear/Views/Company/Helpers/TransactionList.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/TransactionList.swift Tue Jun 08 11:46:58 2021 +0200 @@ -8,13 +8,74 @@ import SwiftUI struct TransactionList: View { + var transactions: [InsiderTransactionModel] + @State private var showFullList = false + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + VStack(alignment: .leading) { + HStack { + Text("Latest transactions") + .font(.title3) + .fontWeight(.semibold) + + Spacer() + Button("See all", action: { showFullList = true }) + } + + VStack(alignment: .leading, spacing: 20) { + ForEach(transactions.prefix(3), id: \.self) { transaction in + TransactionRow(transaction: transaction) + } + } + } + .sheet(isPresented: $showFullList) { + TransactionFullList(transactions: transactions) + } } } struct TransactionList_Previews: PreviewProvider { static var previews: some View { - TransactionList() + TransactionList(transactions: + [ + InsiderTransactionModel(filingDate: "2020-01-01", + fullName: "Dennis Concepcion", + postShares: 1234, + reportedTitle: "Director", + transactionCode: "S", + transactionPrice: 20.08, + transactionShares: 12345, + transactionValue: 1234567.0 + ) + ] + ) } } + +struct TransactionFullList: View { + var transactions: [InsiderTransactionModel] + @Environment(\.presentationMode) private var presentationTransactionFullList + + var body: some View { + NavigationView { + ScrollView { + VStack(alignment: .leading, spacing: 20) { + ForEach(transactions, id: \.self) { transaction in + TransactionRow(transaction: transaction) + } + } + .padding() + } + .navigationTitle("Latest transactions") + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + Button(action: { presentationTransactionFullList.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + .imageScale(.large) + } + } + } + } + } +}
--- a/LazyBear/Views/Company/Helpers/TransactionRow.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/TransactionRow.swift Tue Jun 08 11:46:58 2021 +0200 @@ -40,9 +40,11 @@ } Spacer() - VStack(alignment: .trailing) { - Text("\(transaction.transactionShares)") - .foregroundColor(transaction.transactionShares < 0 ? Color(.systemRed): Color(.systemGreen)) + if let transactionShares = transaction.transactionShares { + VStack(alignment: .trailing) { + Text("\(transactionShares)") + .foregroundColor(transactionShares < 0 ? Color(.systemRed): Color(.systemGreen)) + } } } .padding()
--- a/LazyBear/Views/Company/Insiders.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Insiders.swift Tue Jun 08 11:46:58 2021 +0200 @@ -13,12 +13,15 @@ var body: some View { if company.showInsidersView { - if let insiderSummary = company.insidersData.insiderRoster { - InsiderList(insiderSummary: insiderSummary, numberOfRows: 4) - } - - if let insiderTransactions = company.insidersData.insiderTransactions { + VStack { + if let insiderSummary = company.insidersData.insiderRoster { + InsiderList(insiderSummary: insiderSummary) + .padding(.bottom) + } + if let transactions = company.insidersData.insiderTransactions { + TransactionList(transactions: transactions) + } } } else { ProgressView()
--- a/LazyBear/Views/Company/Networking/InsidersResponse.swift Mon Jun 07 20:59:52 2021 +0200 +++ b/LazyBear/Views/Company/Networking/InsidersResponse.swift Tue Jun 08 11:46:58 2021 +0200 @@ -13,6 +13,6 @@ private enum CodingKeys: String, CodingKey { case insiderRoster = "insider_roster" - case insiderTransactions + case insiderTransactions = "insider_transactions" } }