Skip to content

Commit

Permalink
Merge pull request #200 from moneymanagerex/vm-15-infotable
Browse files Browse the repository at this point in the history
migrate Infotable to ViewModel
  • Loading branch information
georgeef authored Nov 3, 2024
2 parents 617f6f3 + 2e9cab5 commit 43f8c7b
Show file tree
Hide file tree
Showing 27 changed files with 347 additions and 76 deletions.
14 changes: 13 additions & 1 deletion MMEX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
925EABAE2CCF8293003CEAB3 /* PayeeValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABAD2CCF8293003CEAB3 /* PayeeValidation.swift */; };
925EABB02CCF82E4003CEAB3 /* Validation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABAF2CCF82E4003CEAB3 /* Validation.swift */; };
925EABB22CCFFC2E003CEAB3 /* Reload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB12CCFFC2E003CEAB3 /* Reload.swift */; };
925EABB62CD6E6EF003CEAB3 /* InfotableList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB52CD6E6EF003CEAB3 /* InfotableList.swift */; };
925EABB82CD6FAC7003CEAB3 /* TransactionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB72CD6FAC7003CEAB3 /* TransactionList.swift */; };
925EABBA2CD6FBF7003CEAB3 /* ScheduledList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB92CD6FBF7003CEAB3 /* ScheduledList.swift */; };
929EF65F2C9FF2DE0051A3E6 /* AssetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF65E2C9FF2DE0051A3E6 /* AssetData.swift */; };
929EF6612C9FF2FD0051A3E6 /* StockData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF6602C9FF2FD0051A3E6 /* StockData.swift */; };
929EF6632C9FF3ED0051A3E6 /* AssetRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF6622C9FF3ED0051A3E6 /* AssetRepository.swift */; };
Expand Down Expand Up @@ -245,6 +248,9 @@
925EABAD2CCF8293003CEAB3 /* PayeeValidation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayeeValidation.swift; sourceTree = "<group>"; };
925EABAF2CCF82E4003CEAB3 /* Validation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Validation.swift; sourceTree = "<group>"; };
925EABB12CCFFC2E003CEAB3 /* Reload.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reload.swift; sourceTree = "<group>"; };
925EABB52CD6E6EF003CEAB3 /* InfotableList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfotableList.swift; sourceTree = "<group>"; };
925EABB72CD6FAC7003CEAB3 /* TransactionList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionList.swift; sourceTree = "<group>"; };
925EABB92CD6FBF7003CEAB3 /* ScheduledList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledList.swift; sourceTree = "<group>"; };
929EF65E2C9FF2DE0051A3E6 /* AssetData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetData.swift; sourceTree = "<group>"; };
929EF6602C9FF2FD0051A3E6 /* StockData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StockData.swift; sourceTree = "<group>"; };
929EF6622C9FF3ED0051A3E6 /* AssetRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetRepository.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -445,13 +451,16 @@
isa = PBXGroup;
children = (
924353462CCD353A0052E4BC /* ListProtocol.swift */,
9243531C2CC5201C0052E4BC /* ManageList.swift */,
925EABB52CD6E6EF003CEAB3 /* InfotableList.swift */,
924353482CCD36890052E4BC /* CurrencyList.swift */,
9243534A2CCD37AE0052E4BC /* AccountList.swift */,
9243534C2CCD38830052E4BC /* AssetList.swift */,
9243534E2CCD39290052E4BC /* StockList.swift */,
925EAB9A2CCDB60B003CEAB3 /* CategoryList.swift */,
924353502CCD39850052E4BC /* PayeeList.swift */,
925EABB72CD6FAC7003CEAB3 /* TransactionList.swift */,
925EABB92CD6FBF7003CEAB3 /* ScheduledList.swift */,
9243531C2CC5201C0052E4BC /* ManageList.swift */,
);
path = List;
sourceTree = "<group>";
Expand Down Expand Up @@ -835,7 +844,9 @@
9208240E2CA4C4FA00388AB2 /* ReportData.swift in Sources */,
925EAB952CCD8341003CEAB3 /* RepositoryReadView.swift in Sources */,
929EF6652C9FF3FB0051A3E6 /* StockRepository.swift in Sources */,
925EABB82CD6FAC7003CEAB3 /* TransactionList.swift in Sources */,
A3C142502C8B366400D3CEC0 /* PayeeListView.swift in Sources */,
925EABBA2CD6FBF7003CEAB3 /* ScheduledList.swift in Sources */,
925EABB22CCFFC2E003CEAB3 /* Reload.swift in Sources */,
A337428A2CA8E72C00698466 /* InsightsSummary.swift in Sources */,
A3C142672C8F2AF500D3CEC0 /* TransactionData.swift in Sources */,
Expand Down Expand Up @@ -920,6 +931,7 @@
924353172CC51F8E0052E4BC /* StockReload.swift in Sources */,
A3363EE32C9323A5004696C7 /* CategoryEditView.swift in Sources */,
920824102CA4C5CD00388AB2 /* BudgetYearRepository.swift in Sources */,
925EABB62CD6E6EF003CEAB3 /* InfotableList.swift in Sources */,
920824202CA4E5C200388AB2 /* TagLinkData.swift in Sources */,
A3C142652C8ED8EA00D3CEC0 /* AccountEditView.swift in Sources */,
924353512CCD39850052E4BC /* PayeeList.swift in Sources */,
Expand Down
47 changes: 24 additions & 23 deletions MMEX/App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct ContentView: View {
SidebarView(selectedTab: $selectedTab)
} detail: {
TabContentView(
vm: vm,
selectedTab: $selectedTab,
isDocumentPickerPresented: $isDocumentPickerPresented,
isNewDocumentPickerPresented: $isNewDocumentPickerPresented,
Expand All @@ -66,11 +67,11 @@ struct ContentView: View {
let insightsViewModel = InsightsViewModel(env: env)
let infotableViewModel = TransactionViewModel(env: env)
TabView(selection: $selectedTab) {
checkingTab(viewModel: infotableViewModel)
insightsTab(viewModel: insightsViewModel)
enterTab(viewModel: infotableViewModel)
managementTab(viewModel: infotableViewModel, vm: vm)
settingsTab(viewModel: infotableViewModel)
checkingTab(vm: vm, viewModel: infotableViewModel)
insightsTab(vm: vm, viewModel: insightsViewModel)
enterTab(vm: vm, viewModel: infotableViewModel)
managementTab(vm: vm, viewModel: infotableViewModel)
settingsTab(vm: vm, viewModel: infotableViewModel)
}
.onChange(of: selectedTab) { _, tab in
if tab == 2 { isPresentingTransactionAddView = true }
Expand Down Expand Up @@ -132,9 +133,9 @@ struct ContentView: View {
}

// Transaction tab
private func checkingTab(viewModel: TransactionViewModel) -> some View {
private func checkingTab(vm: ViewModel, viewModel: TransactionViewModel) -> some View {
NavigationView {
CheckingView(viewModel: viewModel)
CheckingView(vm: vm, viewModel: viewModel)
.navigationBarTitle("Latest Transactions", displayMode: .inline)
}
.tabItem {
Expand All @@ -144,9 +145,9 @@ struct ContentView: View {
}

// Insights tab
private func insightsTab(viewModel: InsightsViewModel) -> some View {
private func insightsTab(vm: ViewModel, viewModel: InsightsViewModel) -> some View {
NavigationView {
InsightsView(viewModel: viewModel)
InsightsView(vm: vm, viewModel: viewModel)
//.navigationBarTitle("Reports and Insights", displayMode: .inline)
}
.tabItem {
Expand All @@ -156,9 +157,9 @@ struct ContentView: View {
}

// Add transaction tab
private func enterTab(viewModel: TransactionViewModel) -> some View {
private func enterTab(vm: ViewModel, viewModel: TransactionViewModel) -> some View {
NavigationView {
EnterView(viewModel: viewModel, selectedTab: $selectedTab)
EnterView(vm: vm, viewModel: viewModel, selectedTab: $selectedTab)
// .navigationBarTitle("Enter Transaction", displayMode: .inline)
}
.tabItem {
Expand All @@ -169,13 +170,13 @@ struct ContentView: View {

// Management tab
private func managementTab(
viewModel: TransactionViewModel,
vm: ViewModel
vm: ViewModel,
viewModel: TransactionViewModel
) -> some View {
NavigationView {
ManageView(
viewModel: viewModel,
vm: vm,
viewModel: viewModel,
isDocumentPickerPresented: $isDocumentPickerPresented,
isNewDocumentPickerPresented: $isNewDocumentPickerPresented,
isSampleDocument: $isSampleDocument
Expand All @@ -189,9 +190,9 @@ struct ContentView: View {
}

// Settings tab
private func settingsTab(viewModel: TransactionViewModel) -> some View {
private func settingsTab(vm: ViewModel, viewModel: TransactionViewModel) -> some View {
NavigationView {
SettingsView(viewModel: viewModel)
SettingsView(vm: vm, viewModel: viewModel)
//.navigationBarTitle("Settings", displayMode: .inline)
}
.tabItem {
Expand Down Expand Up @@ -261,41 +262,41 @@ struct SidebarView: View {
}

struct TabContentView: View {
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@Binding var selectedTab: Int
@Binding var isDocumentPickerPresented: Bool
@Binding var isNewDocumentPickerPresented: Bool
@Binding var isSampleDocument: Bool
@EnvironmentObject var env: EnvironmentManager // Access EnvironmentManager

var body: some View {
log.trace("TabContentView.body")
// Use @StateObject to manage the lifecycle of TransactionViewModel
let insightsViewModel = InsightsViewModel(env: env)
let infotableViewModel = TransactionViewModel(env: env)
let expViewModel = ViewModel(env: env)
// Here we ensure that there's no additional NavigationStack or NavigationView
return Group {
switch selectedTab {
case 0:
CheckingView(viewModel: infotableViewModel) // Summary and Edit feature
CheckingView(vm: vm, viewModel: infotableViewModel) // Summary and Edit feature
.navigationBarTitle("Latest Transactions", displayMode: .inline)
case 1:
InsightsView(viewModel: insightsViewModel)
InsightsView(vm: vm, viewModel: insightsViewModel)
.navigationBarTitle("Reports and Insights", displayMode: .inline)
case 2:
EnterView(viewModel: infotableViewModel, selectedTab: $selectedTab)
EnterView(vm: vm, viewModel: infotableViewModel, selectedTab: $selectedTab)
.navigationBarTitle("Enter Transaction", displayMode: .inline)
case 3:
ManageView(
vm: vm,
viewModel:infotableViewModel,
vm: expViewModel,
isDocumentPickerPresented: $isDocumentPickerPresented,
isNewDocumentPickerPresented: $isNewDocumentPickerPresented,
isSampleDocument: $isSampleDocument
)
.navigationBarTitle("Manage", displayMode: .inline)
case 4:
SettingsView(viewModel: infotableViewModel)
SettingsView(vm: vm, viewModel: infotableViewModel)
.navigationBarTitle("Settings", displayMode: .inline)
default:
EmptyView()
Expand Down
3 changes: 3 additions & 0 deletions MMEX/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
},
"Asset" : {
"extractionState" : "manual"
},
"Auxiliary Data" : {

},
"Base Currency" : {

Expand Down
13 changes: 9 additions & 4 deletions MMEX/View/Category/CategoryListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import SwiftUI

struct CategoryListView: View {
@EnvironmentObject var env: EnvironmentManager // Access EnvironmentManager
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: TransactionViewModel

@State private var isPresentingAddView = false
@State private var newCategory = CategoryData()
@State private var searchQuery: String = "" // New: Search query
Expand Down Expand Up @@ -55,6 +56,10 @@ struct CategoryListView: View {
}

#Preview {
CategoryListView(viewModel: TransactionViewModel(env: EnvironmentManager.sampleData))
.environmentObject(EnvironmentManager.sampleData)
let env = EnvironmentManager.sampleData
CategoryListView(
vm: ViewModel(env: env),
viewModel: TransactionViewModel(env: env)
)
.environmentObject(env)
}
8 changes: 6 additions & 2 deletions MMEX/View/Checking/CheckingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct CheckingView: View {
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: TransactionViewModel

@State private var searchQuery: String = "" // New: Search query
Expand Down Expand Up @@ -69,6 +70,7 @@ struct CheckingView: View {

func transactionView(_ txn: TransactionData, for day: String) -> some View {
NavigationLink(destination: TransactionDetailView(
vm: vm,
viewModel: viewModel,
accountId: $viewModel.accountId,
categories: $viewModel.categories,
Expand Down Expand Up @@ -197,8 +199,10 @@ struct CheckingView: View {
}

#Preview {
let env = EnvironmentManager.sampleData
CheckingView(
viewModel: TransactionViewModel(env: EnvironmentManager.sampleData)
vm: ViewModel(env: env),
viewModel: TransactionViewModel(env: env)
)
.environmentObject(EnvironmentManager.sampleData)
.environmentObject(env)
}
4 changes: 3 additions & 1 deletion MMEX/View/Enter/EnterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import SwiftUI

struct EnterView: View {
@State var newTxn: TransactionData = TransactionData()
@EnvironmentObject var env: EnvironmentManager // Access EnvironmentManager
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: TransactionViewModel
@Binding var selectedTab: Int // Bind to the selected tab

Expand All @@ -21,6 +22,7 @@ struct EnterView: View {
var body: some View {
NavigationStack {
TransactionEditView(
vm: vm,
viewModel: viewModel,
accountId: $accountId,
categories: $viewModel.categories,
Expand Down
7 changes: 5 additions & 2 deletions MMEX/View/Insights/InsightsAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct InsightsAccountView: View {
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: InsightsViewModel
@Binding var statusChoice: Int
@State private var expandedSections: [AccountType: Bool] = [:]
Expand Down Expand Up @@ -145,14 +146,16 @@ struct InsightsAccountView: View {
}

#Preview {
let env = EnvironmentManager.sampleData
NavigationStack {
ScrollView {
InsightsAccountView(
viewModel: InsightsViewModel(env: EnvironmentManager.sampleData),
vm: ViewModel(env: env),
viewModel: InsightsViewModel(env: env),
statusChoice: .constant(0)
)
}
.navigationBarTitleDisplayMode(.inline)
}
.environmentObject(EnvironmentManager.sampleData)
.environmentObject(env)
}
8 changes: 6 additions & 2 deletions MMEX/View/Insights/InsightsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Charts

struct InsightsView: View {
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: InsightsViewModel
@State var statusChoice: Int = 0
@State var accountBalanceIsExpanded = true
Expand All @@ -29,6 +30,7 @@ struct InsightsView: View {
}
} ) { if accountBalanceIsExpanded {
InsightsAccountView(
vm: vm,
viewModel: viewModel,
statusChoice: $statusChoice
)
Expand Down Expand Up @@ -101,8 +103,10 @@ struct InsightsView: View {
}

#Preview {
let env = EnvironmentManager.sampleData
InsightsView(
viewModel: InsightsViewModel(env: EnvironmentManager.sampleData)
vm: ViewModel(env: env),
viewModel: InsightsViewModel(env: env)
)
.environmentObject(EnvironmentManager.sampleData)
.environmentObject(env)
}
20 changes: 12 additions & 8 deletions MMEX/View/Manage/ManageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import SwiftUI

struct ManageView: View {
@EnvironmentObject var env: EnvironmentManager // Access EnvironmentManager
@ObservedObject var viewModel: TransactionViewModel
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var vm: ViewModel
@ObservedObject var viewModel: TransactionViewModel
@Binding var isDocumentPickerPresented: Bool
@Binding var isNewDocumentPickerPresented: Bool
@Binding var isSampleDocument: Bool
Expand Down Expand Up @@ -42,7 +42,7 @@ struct ManageView: View {
count: vm.stockList.count
)
}
NavigationLink(destination: CategoryListView(viewModel: viewModel)) {
NavigationLink(destination: CategoryListView(vm: vm, viewModel: viewModel)) {
env.theme.group.manageItem(
name: { Text(CategoryData.dataName.1) },
count: vm.categoryList.count
Expand All @@ -54,14 +54,17 @@ struct ManageView: View {
count: vm.payeeList.count
)
}
NavigationLink(destination: TransactionListView(viewModel: viewModel)) {
NavigationLink(destination: TransactionListView(vm: vm, viewModel: viewModel)) {
env.theme.group.manageItem(
name: { Text(TransactionData.dataName.1) },
count: vm.transactionCount
count: vm.transactionList.count
)
}
}

Section(header: Text("Auxiliary Data")) {
}

Section(header: Text("Database")) {
Button(action: {
isDocumentPickerPresented = true
Expand Down Expand Up @@ -119,12 +122,13 @@ struct ManageView: View {
}

#Preview {
let env = EnvironmentManager.sampleData
ManageView(
viewModel: TransactionViewModel(env: EnvironmentManager.sampleData),
vm: ViewModel(env: EnvironmentManager.sampleData),
vm: ViewModel(env: env),
viewModel: TransactionViewModel(env: env),
isDocumentPickerPresented: .constant(false),
isNewDocumentPickerPresented: .constant(false),
isSampleDocument: .constant(false)
)
.environmentObject(EnvironmentManager.sampleData)
.environmentObject(env)
}
Loading

0 comments on commit 43f8c7b

Please sign in to comment.