2019-09-30 03:02:10 +00:00
|
|
|
//
|
|
|
|
// TabbedBudgetView.swift
|
|
|
|
// Budget
|
|
|
|
//
|
|
|
|
// Created by Billy Brawner on 9/29/19.
|
|
|
|
// Copyright © 2019 William Brawner. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-01-03 17:56:43 +00:00
|
|
|
import TwigsCore
|
2019-09-30 03:02:10 +00:00
|
|
|
|
|
|
|
struct TabbedBudgetView: View {
|
2021-11-03 17:17:18 +00:00
|
|
|
@EnvironmentObject var authenticationDataStore: AuthenticationDataStore
|
2022-01-03 17:56:43 +00:00
|
|
|
@EnvironmentObject var budgetDataStore: BudgetsDataStore
|
2022-01-07 00:24:50 +00:00
|
|
|
@EnvironmentObject var apiService: TwigsApiService
|
2022-04-16 02:20:31 +00:00
|
|
|
@AppStorage("budget_tab") var tabSelection: Int = 0
|
2019-09-30 03:49:03 +00:00
|
|
|
|
2021-11-03 17:17:18 +00:00
|
|
|
@ViewBuilder
|
|
|
|
var mainView: some View {
|
|
|
|
if case let .success(budget) = budgetDataStore.budget {
|
|
|
|
TabView(selection: $tabSelection) {
|
|
|
|
NavigationView {
|
|
|
|
BudgetDetailsView(budget: budget)
|
|
|
|
.navigationBarTitle("overview")
|
2021-12-08 03:21:46 +00:00
|
|
|
.navigationBarItems(leading: HStack {
|
|
|
|
Button("budgets", action: {
|
|
|
|
self.budgetDataStore.showBudgetSelection = true
|
|
|
|
}).padding()
|
|
|
|
})
|
2021-11-03 17:17:18 +00:00
|
|
|
}
|
2021-10-10 02:27:54 +00:00
|
|
|
.tabItem {
|
2021-10-10 03:23:49 +00:00
|
|
|
Image(systemName: "chart.line.uptrend.xyaxis.circle.fill")
|
2021-10-22 03:08:06 +00:00
|
|
|
Text("overview")
|
2021-10-10 02:27:54 +00:00
|
|
|
}
|
|
|
|
.tag(0)
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("1")
|
2021-11-03 17:17:18 +00:00
|
|
|
NavigationView {
|
2022-01-05 02:51:38 +00:00
|
|
|
TransactionListView<EmptyView>(apiService: apiService, budget: budget)
|
2021-11-03 17:17:18 +00:00
|
|
|
.navigationBarTitle("transactions")
|
|
|
|
}
|
2021-09-11 15:01:22 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "dollarsign.circle.fill")
|
|
|
|
Text("transactions")
|
|
|
|
}
|
2021-10-13 12:32:58 +00:00
|
|
|
.tag(1)
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("2")
|
2021-11-03 17:17:18 +00:00
|
|
|
NavigationView {
|
|
|
|
CategoryListView(budget)
|
|
|
|
.navigationBarTitle("categories")
|
2021-09-11 15:01:22 +00:00
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "chart.pie.fill")
|
|
|
|
Text("categories")
|
2021-10-18 12:34:17 +00:00
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
.tag(2)
|
|
|
|
.keyboardShortcut("3")
|
|
|
|
NavigationView {
|
2022-01-03 17:56:43 +00:00
|
|
|
RecurringTransactionsListView(dataStore: RecurringTransactionDataStore(apiService), budget: budget)
|
2021-12-08 03:22:06 +00:00
|
|
|
.navigationBarTitle("recurring_transactions")
|
2021-11-03 17:17:18 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2021-12-08 03:22:06 +00:00
|
|
|
Image(systemName: "arrow.triangle.2.circlepath.circle.fill")
|
|
|
|
Text("recurring")
|
2021-11-03 17:17:18 +00:00
|
|
|
}
|
|
|
|
.tag(3)
|
|
|
|
.keyboardShortcut("4")
|
2022-01-05 02:51:38 +00:00
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
} else {
|
2021-12-01 03:03:46 +00:00
|
|
|
ActivityIndicator(isAnimating: .constant(true), style: .large)
|
2021-11-03 17:17:18 +00:00
|
|
|
}
|
2019-09-30 03:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 17:17:18 +00:00
|
|
|
var body: some View {
|
|
|
|
mainView.sheet(isPresented: $authenticationDataStore.showLogin,
|
|
|
|
onDismiss: {
|
2022-01-03 17:56:43 +00:00
|
|
|
Task {
|
|
|
|
await self.budgetDataStore.getBudgets()
|
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
},
|
|
|
|
content: {
|
|
|
|
LoginView()
|
|
|
|
.environmentObject(authenticationDataStore)
|
2021-12-01 03:03:46 +00:00
|
|
|
.onDisappear {
|
2022-01-03 17:56:43 +00:00
|
|
|
Task {
|
|
|
|
await self.budgetDataStore.getBudgets()
|
|
|
|
}
|
2021-12-01 03:03:46 +00:00
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
}).sheet(isPresented: $budgetDataStore.showBudgetSelection,
|
|
|
|
content: {
|
2021-12-08 03:21:46 +00:00
|
|
|
List {
|
2021-12-14 13:15:32 +00:00
|
|
|
BudgetListsView().environmentObject(budgetDataStore)
|
2021-12-08 03:21:46 +00:00
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
})
|
2021-12-01 03:03:46 +00:00
|
|
|
.interactiveDismissDisabled(true)
|
2019-09-30 03:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-03 17:17:18 +00:00
|
|
|
|
|
|
|
|
2019-09-30 03:02:10 +00:00
|
|
|
//
|
|
|
|
//struct TabbedBudgetView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// TabbedBudgetView()
|
|
|
|
// }
|
|
|
|
//}
|