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 {
|
2022-05-18 01:04:27 +00:00
|
|
|
@EnvironmentObject var dataStore: DataStore
|
2021-12-08 03:21:46 +00:00
|
|
|
@State var isSelectingBudget = true
|
|
|
|
@State var hasSelectedBudget = false
|
|
|
|
@State var tabSelection: Int? = 0
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var mainView: some View {
|
2022-05-18 01:04:27 +00:00
|
|
|
if case let .success(budget) = self.dataStore.budget {
|
2023-03-05 04:56:15 +00:00
|
|
|
NavigationSplitView(sidebar: {
|
|
|
|
VStack {
|
|
|
|
List(selection: $tabSelection) {
|
|
|
|
NavigationLink(
|
|
|
|
value: 0,
|
|
|
|
label: { Label("overview", systemImage: "chart.line.uptrend.xyaxis") }
|
|
|
|
)
|
2021-12-10 04:35:56 +00:00
|
|
|
.keyboardShortcut("1")
|
2023-03-05 04:56:15 +00:00
|
|
|
NavigationLink(
|
|
|
|
value: 1,
|
|
|
|
label: { Label("transactions", systemImage: "dollarsign.circle") }
|
|
|
|
)
|
2021-12-10 04:35:56 +00:00
|
|
|
.keyboardShortcut("2")
|
2023-03-05 04:56:15 +00:00
|
|
|
NavigationLink(
|
|
|
|
value: 2,
|
|
|
|
label: { Label("categories", systemImage: "chart.pie") }
|
|
|
|
)
|
2021-12-10 04:35:56 +00:00
|
|
|
.keyboardShortcut("3")
|
2023-03-05 04:56:15 +00:00
|
|
|
NavigationLink(
|
|
|
|
value: 3,
|
|
|
|
label: { Label("recurring_transactions", systemImage: "arrow.triangle.2.circlepath") }
|
|
|
|
)
|
2021-12-10 04:35:56 +00:00
|
|
|
.keyboardShortcut("4")
|
2023-03-05 04:56:15 +00:00
|
|
|
}
|
2021-12-08 03:21:46 +00:00
|
|
|
BudgetListsView()
|
|
|
|
}
|
|
|
|
.navigationTitle(budget.name)
|
2023-03-05 04:56:15 +00:00
|
|
|
}, content: {
|
|
|
|
if tabSelection == 0, let budget = dataStore.selectedBudget {
|
|
|
|
BudgetDetailsView(budget: budget)
|
|
|
|
.navigationTitle("budgets")
|
|
|
|
} else if tabSelection == 1 {
|
|
|
|
TransactionListView<EmptyView>()
|
|
|
|
.navigationTitle("transactions")
|
|
|
|
} else if tabSelection == 2, let budget = dataStore.selectedBudget {
|
|
|
|
CategoryListView(budget)
|
|
|
|
.navigationTitle("categories")
|
|
|
|
} else if tabSelection == 3 {
|
|
|
|
RecurringTransactionsListView()
|
|
|
|
.navigationTitle("recurring_transactions")
|
|
|
|
} else {
|
|
|
|
ActivityIndicator(isAnimating: .constant(true), style: .large)
|
2022-01-07 00:25:22 +00:00
|
|
|
}
|
2023-03-05 04:56:15 +00:00
|
|
|
}, detail: {
|
|
|
|
if let _ = dataStore.selectedTransaction {
|
|
|
|
TransactionDetailsView()
|
|
|
|
.navigationTitle("details")
|
|
|
|
.onDisappear {
|
|
|
|
dataStore.selectedTransaction = nil
|
|
|
|
}
|
|
|
|
} else if let _ = dataStore.selectedCategory {
|
|
|
|
if let budget = dataStore.selectedBudget {
|
|
|
|
CategoryDetailsView(budget, categoryDataStore: CategoryDataStore(dataStore.apiService))
|
|
|
|
.navigationTitle(dataStore.selectedCategory?.title ?? "")
|
|
|
|
}
|
|
|
|
} else if let _ = dataStore.selectedRecurringTransaction {
|
|
|
|
RecurringTransactionDetailsView()
|
|
|
|
.navigationTitle("details")
|
|
|
|
}
|
|
|
|
})
|
2021-12-08 03:21:46 +00:00
|
|
|
} else {
|
|
|
|
ActivityIndicator(isAnimating: .constant(true), style: .large)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var body: some View {
|
|
|
|
mainView
|
2022-05-18 01:04:27 +00:00
|
|
|
.sheet(isPresented: $dataStore.showLogin,
|
2021-12-10 04:35:56 +00:00
|
|
|
content: {
|
|
|
|
LoginView()
|
2022-05-18 01:04:27 +00:00
|
|
|
.environmentObject(dataStore)
|
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()
|
|
|
|
// }
|
|
|
|
//}
|