Clean up views and fix transaction loading

Signed-off-by: Billy Brawner <billy@wbrawner.com>
This commit is contained in:
Billy Brawner 2019-10-02 19:52:40 -07:00
parent 3d2d221f32
commit 5f9c14f64f
8 changed files with 56 additions and 16 deletions

View file

@ -104,7 +104,7 @@
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "755CC7AE-D48D-40BE-8CB5-9CE168241BED"
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Budget/Network/BudgetApiService.swift"

View file

@ -12,12 +12,14 @@ struct ContentView: View {
@ObservedObject var userData: UserDataStore
var body: some View {
Group {
if showLogin() {
LoginView(userData)
} else {
TabbedBudgetView(userData, dataStoreProvider: dataStoreProvider)
}
stateContent
}
var stateContent: AnyView {
if showLogin() {
return AnyView(LoginView(userData))
} else {
return AnyView(TabbedBudgetView(userData, dataStoreProvider: dataStoreProvider))
}
}

View file

@ -202,7 +202,7 @@ class RequestHelper {
}
}
return buildRequest(endPoint: combinedEndPoint, method: "GET")
return buildRequest(endPoint: combinedEndPoint, method: "GET")
}
func post<ResultType: Codable>(
@ -291,14 +291,26 @@ extension Encodable {
}
extension Date {
var dateFormatter: DateFormatter {
var iso8601DateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
return dateFormatter
}
var localeDateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
dateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "yyyyMMdd", options: 0, locale: Locale.current)
return dateFormatter
}
func toISO8601String() -> String {
return dateFormatter.string(from: self)
return iso8601DateFormatter.string(from: self)
}
func toLocaleString() -> String {
return localeDateFormatter.string(from: self)
}
}

View file

@ -16,8 +16,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
override init() {
// TODO: Dependency injection?
#if DEBUG
let baseUrl = "http://localhost:8080"
// let baseUrl = "https://budget-api.intra.wbrawner.com"
// let baseUrl = "http://localhost:8080"
let baseUrl = "https://budget-api.intra.wbrawner.com"
#else
let baseUrl = "https://budget-api.intra.wbrawner.com"
#endif

View file

@ -16,6 +16,14 @@ struct TabbedBudgetView: View {
NavigationView {
TransactionListView(dataStoreProvider)
.navigationBarTitle("transactions")
.navigationBarItems(
leading: NavigationLink(destination: EmptyView()) {
Text("filter")
},
trailing: NavigationLink(destination: EmptyView().navigationBarTitle("add_transaction")) {
Text("add")
}
)
}.tabItem {
Image(systemName: "dollarsign.circle.fill")
Text("transactions")
@ -28,7 +36,7 @@ struct TabbedBudgetView: View {
Image(systemName: "person.circle.fill")
Text("profile")
}
}
}.edgesIgnoringSafeArea(.top)
}
let dataStoreProvider: DataStoreProvider

View file

@ -52,14 +52,22 @@ struct TransactionListItemView: View {
HStack {
VStack(alignment: .leading) {
Text(verbatim: transaction.title)
Text(verbatim: transaction.date.toISO8601String())
.lineLimit(1)
.font(.system(size: 20))
Text(verbatim: transaction.date.toLocaleString())
.lineLimit(1)
.font(.system(size: 16))
.foregroundColor(.gray)
.multilineTextAlignment(.trailing)
}
Spacer()
VStack(alignment: .trailing) {
Text(verbatim: self.numberFormatter.string(from: NSNumber(value: Double(transaction.amount) / 100.0)) ?? "")
.foregroundColor(transaction.expense ? .red : .green)
.multilineTextAlignment(.trailing)
}
.padding(.leading)
}
}.padding(5.0)
}
}

View file

@ -6,6 +6,10 @@
Copyright © 2019 William Brawner. All rights reserved.
*/
// MARK: Generic
"add" = "Add";
"filter" = "Filter";
// MARK: Login
"info_login" = "Login to start managing your budget";
"prompt_username" = "Username";
@ -16,6 +20,7 @@
// MARK: Transactions
"transactions" = "Transactions";
"add_transaction" = "Add Transaction";
// MARK: Budgets
"budgets" = "Budgets";

View file

@ -6,6 +6,10 @@
Copyright © 2019 William Brawner. All rights reserved.
*/
// MARK: Generic
"add" = "Agregar";
"filter" = "Filtrar";
// MARK: Login
"info_login" = "Inicia sesión para empezar a manejar su presupuseto";
"prompt_username" = "Nombre de usuario";
@ -16,6 +20,7 @@
// MARK: Transactions
"transactions" = "Transacciones";
"add_transaction" = "Agregar Transacción";
// MARK: Budgets
"budgets" = "Presupuestos";