2021-12-08 03:21:46 +00:00
|
|
|
//
|
|
|
|
// SidebarBudgetView.swift
|
|
|
|
// Twigs
|
|
|
|
//
|
|
|
|
// Created by William Brawner on 12/7/21.
|
|
|
|
// Copyright © 2021 William Brawner. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-01-03 17:56:43 +00:00
|
|
|
import TwigsCore
|
2021-12-08 03:21:46 +00:00
|
|
|
|
|
|
|
struct SidebarBudgetView: View {
|
|
|
|
@EnvironmentObject var authenticationDataStore: AuthenticationDataStore
|
2022-01-03 17:56:43 +00:00
|
|
|
@EnvironmentObject var budgetDataStore: BudgetsDataStore
|
2021-12-08 03:21:46 +00:00
|
|
|
let apiService: TwigsApiService
|
|
|
|
@State var isSelectingBudget = true
|
|
|
|
@State var hasSelectedBudget = false
|
|
|
|
@State var isAddingTransaction = false
|
|
|
|
@State var tabSelection: Int? = 0
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var mainView: some View {
|
2022-01-03 17:56:43 +00:00
|
|
|
if case let .success(budget) = self.budgetDataStore.budget {
|
2021-12-08 03:21:46 +00:00
|
|
|
NavigationView {
|
|
|
|
List {
|
|
|
|
NavigationLink(
|
|
|
|
tag: 0,
|
|
|
|
selection: $tabSelection,
|
2021-12-10 04:35:56 +00:00
|
|
|
destination: { BudgetDetailsView(budget: budget).navigationBarTitle("overview")
|
|
|
|
},
|
|
|
|
label: { Label("overview", systemImage: "chart.line.uptrend.xyaxis") }
|
2021-12-08 03:21:46 +00:00
|
|
|
)
|
2021-12-10 04:35:56 +00:00
|
|
|
.keyboardShortcut("1")
|
2021-12-08 03:21:46 +00:00
|
|
|
NavigationLink(
|
|
|
|
tag: 1,
|
|
|
|
selection: $tabSelection,
|
2022-01-03 17:56:43 +00:00
|
|
|
destination: { TransactionListView<EmptyView>(budget).navigationBarTitle("transactions") },
|
2021-12-10 04:35:56 +00:00
|
|
|
label: { Label("transactions", systemImage: "dollarsign.circle") })
|
|
|
|
.keyboardShortcut("2")
|
2021-12-08 03:21:46 +00:00
|
|
|
NavigationLink(
|
|
|
|
tag: 2,
|
|
|
|
selection: $tabSelection,
|
|
|
|
destination: { CategoryListView(budget).navigationBarTitle("categories") },
|
2021-12-10 04:35:56 +00:00
|
|
|
label: { Label("categories", systemImage: "chart.pie") })
|
|
|
|
.keyboardShortcut("3")
|
2021-12-08 03:21:46 +00:00
|
|
|
NavigationLink(
|
|
|
|
tag: 3,
|
|
|
|
selection: $tabSelection,
|
2022-01-03 17:56:43 +00:00
|
|
|
destination: { RecurringTransactionsListView(dataStore: RecurringTransactionDataStore(apiService), budget: budget).navigationBarTitle("recurring_transactions") },
|
2021-12-10 04:35:56 +00:00
|
|
|
label: { Label("recurring_transactions", systemImage: "arrow.triangle.2.circlepath") })
|
|
|
|
.keyboardShortcut("4")
|
2021-12-08 03:21:46 +00:00
|
|
|
BudgetListsView()
|
|
|
|
}
|
|
|
|
.navigationTitle(budget.name)
|
2022-01-03 17:56:43 +00:00
|
|
|
}.navigationViewStyle(.columns)
|
|
|
|
.environmentObject(TransactionDataStore(apiService))
|
|
|
|
.environmentObject(CategoryListDataStore(apiService))
|
2021-12-10 04:35:56 +00:00
|
|
|
.environmentObject(budgetDataStore)
|
|
|
|
.environmentObject(UserDataStore(apiService))
|
2021-12-08 03:21:46 +00:00
|
|
|
} else {
|
|
|
|
ActivityIndicator(isAnimating: .constant(true), style: .large)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var body: some View {
|
|
|
|
mainView
|
2021-12-10 04:35:56 +00:00
|
|
|
.sheet(isPresented: $authenticationDataStore.showLogin,
|
|
|
|
onDismiss: {
|
2022-01-03 17:56:43 +00:00
|
|
|
Task {
|
|
|
|
await self.budgetDataStore.getBudgets()
|
|
|
|
}
|
2021-12-10 04:35:56 +00:00
|
|
|
},
|
|
|
|
content: {
|
|
|
|
LoginView()
|
|
|
|
.environmentObject(authenticationDataStore)
|
|
|
|
.onDisappear {
|
2022-01-03 17:56:43 +00:00
|
|
|
Task {
|
|
|
|
await self.budgetDataStore.getBudgets()
|
|
|
|
}
|
2021-12-10 04:35:56 +00:00
|
|
|
}
|
|
|
|
})
|
2021-12-08 03:21:46 +00:00
|
|
|
.interactiveDismissDisabled(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//struct SidebarBudgetView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// SidebarBudgetView()
|
|
|
|
// }
|
|
|
|
//}
|