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
|
|
|
|
|
|
|
|
struct TabbedBudgetView: View {
|
2021-10-10 03:23:49 +00:00
|
|
|
@EnvironmentObject var budgetDataStore: BudgetsDataStore
|
2021-10-10 00:32:57 +00:00
|
|
|
@EnvironmentObject var categoryDataStore: CategoryDataStore
|
2021-10-06 01:26:54 +00:00
|
|
|
let budget: Budget
|
2019-10-11 02:30:43 +00:00
|
|
|
@State var isAddingTransaction = false
|
2021-10-13 12:32:58 +00:00
|
|
|
@State var tabSelection: Int = 0
|
2019-09-30 03:49:03 +00:00
|
|
|
|
2019-09-30 03:02:10 +00:00
|
|
|
var body: some View {
|
2021-10-13 12:32:58 +00:00
|
|
|
TabView(selection: $tabSelection) {
|
2021-10-10 02:27:54 +00:00
|
|
|
BudgetDetailsView(budget: self.budget)
|
|
|
|
.tabItem {
|
2021-10-10 03:23:49 +00:00
|
|
|
Image(systemName: "chart.line.uptrend.xyaxis.circle.fill")
|
2021-10-10 02:27:54 +00:00
|
|
|
Text("Overview")
|
|
|
|
}
|
|
|
|
.tag(0)
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("1")
|
2021-10-06 01:26:54 +00:00
|
|
|
TransactionListView(self.budget)
|
2021-10-10 02:03:01 +00:00
|
|
|
.sheet(isPresented: $isAddingTransaction,
|
|
|
|
onDismiss: {
|
|
|
|
isAddingTransaction = false
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
AddTransactionView(showSheet: self.$isAddingTransaction, budgetId: self.budget.id)
|
2021-09-11 15:01:22 +00:00
|
|
|
.navigationBarTitle("add_transaction")
|
|
|
|
})
|
|
|
|
.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-10-13 12:32:58 +00:00
|
|
|
CategoryListView(self.budget).tabItem {
|
2019-10-01 03:31:22 +00:00
|
|
|
Image(systemName: "chart.pie.fill")
|
2021-09-11 15:01:22 +00:00
|
|
|
Text("categories")
|
|
|
|
}
|
2021-10-13 12:32:58 +00:00
|
|
|
.tag(2)
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("3")
|
2021-10-06 01:26:54 +00:00
|
|
|
ProfileView().tabItem {
|
2019-10-01 03:31:22 +00:00
|
|
|
Image(systemName: "person.circle.fill")
|
|
|
|
Text("profile")
|
2019-09-30 03:49:03 +00:00
|
|
|
}
|
2021-10-13 12:32:58 +00:00
|
|
|
.tag(3)
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("4")
|
2021-09-11 15:01:22 +00:00
|
|
|
}.navigationBarItems(
|
|
|
|
trailing: HStack {
|
2021-10-18 12:11:11 +00:00
|
|
|
if tabSelection == 1 {
|
|
|
|
Button(action: {
|
|
|
|
self.isAddingTransaction = true
|
|
|
|
}) {
|
|
|
|
Image(systemName: "plus")
|
|
|
|
.padding()
|
|
|
|
}
|
2021-10-18 12:34:17 +00:00
|
|
|
.keyboardShortcut("n")
|
2021-09-11 15:01:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2021-10-18 12:34:17 +00:00
|
|
|
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("switchTabs"))) { notification in
|
|
|
|
if let tabTag = notification.object as? Int {
|
|
|
|
if 0...3 ~= tabTag {
|
|
|
|
self.tabSelection = tabTag
|
|
|
|
print("Updating tabSelection to \(tabTag)")
|
|
|
|
} else {
|
|
|
|
print("Ignoring value \(tabTag)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-30 03:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 01:26:54 +00:00
|
|
|
init (_ budget: Budget) {
|
2021-09-11 15:01:22 +00:00
|
|
|
self.budget = budget
|
2019-09-30 03:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//struct TabbedBudgetView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// TabbedBudgetView()
|
|
|
|
// }
|
|
|
|
//}
|