twigs-ios/Twigs/TabbedBudgetView.swift

105 lines
3.5 KiB
Swift
Raw Normal View History

//
// 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
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
@AppStorage("budget_tab") var tabSelection: Int = 0
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 {
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)
.keyboardShortcut("1")
2021-11-03 17:17:18 +00:00
NavigationView {
TransactionListView<EmptyView>(apiService: apiService, budget: budget)
2021-11-03 17:17:18 +00:00
.navigationBarTitle("transactions")
}
.tabItem {
Image(systemName: "dollarsign.circle.fill")
Text("transactions")
}
.tag(1)
.keyboardShortcut("2")
2021-11-03 17:17:18 +00:00
NavigationView {
CategoryListView(budget)
.navigationBarTitle("categories")
}
2021-11-03 17:17:18 +00:00
.tabItem {
Image(systemName: "chart.pie.fill")
Text("categories")
}
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)
.navigationBarTitle("recurring_transactions")
2021-11-03 17:17:18 +00:00
}
.tabItem {
Image(systemName: "arrow.triangle.2.circlepath.circle.fill")
Text("recurring")
2021-11-03 17:17:18 +00:00
}
.tag(3)
.keyboardShortcut("4")
}
2021-11-03 17:17:18 +00:00
} else {
ActivityIndicator(isAnimating: .constant(true), style: .large)
2021-11-03 17:17:18 +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)
.onDisappear {
2022-01-03 17:56:43 +00:00
Task {
await self.budgetDataStore.getBudgets()
}
}
2021-11-03 17:17:18 +00:00
}).sheet(isPresented: $budgetDataStore.showBudgetSelection,
content: {
2021-12-08 03:21:46 +00:00
List {
BudgetListsView().environmentObject(budgetDataStore)
2021-12-08 03:21:46 +00:00
}
2021-11-03 17:17:18 +00:00
})
.interactiveDismissDisabled(true)
}
}
2021-11-03 17:17:18 +00:00
//
//struct TabbedBudgetView_Previews: PreviewProvider {
// static var previews: some View {
// TabbedBudgetView()
// }
//}