Skip to content

Commit

Permalink
Merge pull request #173 from moneymanagerex/viewmodel-4
Browse files Browse the repository at this point in the history
refine ViewModel
  • Loading branch information
georgeef authored Oct 25, 2024
2 parents 89461e0 + e7c96dd commit 6d42b66
Show file tree
Hide file tree
Showing 22 changed files with 716 additions and 472 deletions.
16 changes: 8 additions & 8 deletions MMEX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@
924353012CBA06210052E4BC /* AccountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353002CBA06210052E4BC /* AccountViewModel.swift */; };
924353032CBB2AB90052E4BC /* ItemTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353022CBB2AB90052E4BC /* ItemTheme.swift */; };
924353052CC3B2E30052E4BC /* RepositoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353042CC3B2E30052E4BC /* RepositoryViewModel.swift */; };
924353092CC4A2590052E4BC /* RepositoryLoadGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353082CC4A2590052E4BC /* RepositoryLoadGroup.swift */; };
924353092CC4A2590052E4BC /* RepositoryGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353082CC4A2590052E4BC /* RepositoryGroup.swift */; };
9243530F2CC516B70052E4BC /* RepositoryLoadMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9243530D2CC516B70052E4BC /* RepositoryLoadMain.swift */; };
924353102CC516B70052E4BC /* RepositoryLoadProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9243530E2CC516B70052E4BC /* RepositoryLoadProtocol.swift */; };
924353152CC51F590052E4BC /* AssetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353142CC51F590052E4BC /* AssetViewModel.swift */; };
924353172CC51F8E0052E4BC /* StockViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353162CC51F8E0052E4BC /* StockViewModel.swift */; };
924353192CC51FA00052E4BC /* PayeeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353182CC51FA00052E4BC /* PayeeViewModel.swift */; };
9243531B2CC51FB10052E4BC /* CurrencyViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9243531A2CC51FB10052E4BC /* CurrencyViewModel.swift */; };
9243531D2CC5201C0052E4BC /* ManageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9243531C2CC5201C0052E4BC /* ManageViewModel.swift */; };
9243531F2CC5A8B70052E4BC /* RepositoryLoadList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9243531E2CC5A8B70052E4BC /* RepositoryLoadList.swift */; };
924353212CC6EFA70052E4BC /* RepositoryLoadAux.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353202CC6EFA70052E4BC /* RepositoryLoadAux.swift */; };
924353252CC8928F0052E4BC /* AccountUpdateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353242CC8928F0052E4BC /* AccountUpdateView.swift */; };
924353272CCAD2780052E4BC /* RepositoryLoadState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924353262CCAD2780052E4BC /* RepositoryLoadState.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 @@ -186,17 +186,17 @@
924353002CBA06210052E4BC /* AccountViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountViewModel.swift; sourceTree = "<group>"; };
924353022CBB2AB90052E4BC /* ItemTheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemTheme.swift; sourceTree = "<group>"; };
924353042CC3B2E30052E4BC /* RepositoryViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryViewModel.swift; sourceTree = "<group>"; };
924353082CC4A2590052E4BC /* RepositoryLoadGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryLoadGroup.swift; sourceTree = "<group>"; };
924353082CC4A2590052E4BC /* RepositoryGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryGroup.swift; sourceTree = "<group>"; };
9243530D2CC516B70052E4BC /* RepositoryLoadMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepositoryLoadMain.swift; sourceTree = "<group>"; };
9243530E2CC516B70052E4BC /* RepositoryLoadProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepositoryLoadProtocol.swift; sourceTree = "<group>"; };
924353142CC51F590052E4BC /* AssetViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetViewModel.swift; sourceTree = "<group>"; };
924353162CC51F8E0052E4BC /* StockViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StockViewModel.swift; sourceTree = "<group>"; };
924353182CC51FA00052E4BC /* PayeeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayeeViewModel.swift; sourceTree = "<group>"; };
9243531A2CC51FB10052E4BC /* CurrencyViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyViewModel.swift; sourceTree = "<group>"; };
9243531C2CC5201C0052E4BC /* ManageViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManageViewModel.swift; sourceTree = "<group>"; };
9243531E2CC5A8B70052E4BC /* RepositoryLoadList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryLoadList.swift; sourceTree = "<group>"; };
924353202CC6EFA70052E4BC /* RepositoryLoadAux.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryLoadAux.swift; sourceTree = "<group>"; };
924353242CC8928F0052E4BC /* AccountUpdateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountUpdateView.swift; sourceTree = "<group>"; };
924353262CCAD2780052E4BC /* RepositoryLoadState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryLoadState.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 @@ -364,11 +364,10 @@
924353132CC5181D0052E4BC /* RepositoryLoad */ = {
isa = PBXGroup;
children = (
924353262CCAD2780052E4BC /* RepositoryLoadState.swift */,
9243530E2CC516B70052E4BC /* RepositoryLoadProtocol.swift */,
9243530D2CC516B70052E4BC /* RepositoryLoadMain.swift */,
924353202CC6EFA70052E4BC /* RepositoryLoadAux.swift */,
9243531E2CC5A8B70052E4BC /* RepositoryLoadList.swift */,
924353082CC4A2590052E4BC /* RepositoryLoadGroup.swift */,
);
path = RepositoryLoad;
sourceTree = "<group>";
Expand Down Expand Up @@ -399,6 +398,7 @@
A3462F632C9426F500F79145 /* InsightsViewModel.swift */,
A350BDC02CA26415006669D5 /* TransactionViewModel.swift */,
924353132CC5181D0052E4BC /* RepositoryLoad */,
924353082CC4A2590052E4BC /* RepositoryGroup.swift */,
924352FE2CB99F1D0052E4BC /* RepositorySearch.swift */,
924353042CC3B2E30052E4BC /* RepositoryViewModel.swift */,
9243531C2CC5201C0052E4BC /* ManageViewModel.swift */,
Expand Down Expand Up @@ -727,7 +727,6 @@
A30061782CA3B68300011B1A /* AssetEditView.swift in Sources */,
A37E7D8C2C9AC36800B4ECFC /* LegalView.swift in Sources */,
A3C1425F2C8DE70300D3CEC0 /* EnvironmentManager.swift in Sources */,
9243531F2CC5A8B70052E4BC /* RepositoryLoadList.swift in Sources */,
924353012CBA06210052E4BC /* AccountViewModel.swift in Sources */,
A3C1424E2C8B335900D3CEC0 /* PayeeData.swift in Sources */,
929EF6612C9FF2FD0051A3E6 /* StockData.swift in Sources */,
Expand Down Expand Up @@ -765,6 +764,7 @@
920824282CA60E8400388AB2 /* FieldData.swift in Sources */,
929EF66B2CA03AF90051A3E6 /* Data.swift in Sources */,
A3C142922C8FE11700D3CEC0 /* AccountRepository.swift in Sources */,
924353272CCAD2780052E4BC /* RepositoryLoadState.swift in Sources */,
A3C1422B2C89751500D3CEC0 /* MMEXApp.swift in Sources */,
A39B1B362C99A0C2003E5562 /* CurrencyEditView.swift in Sources */,
A3363EE72C93249D004696C7 /* CategoryAddView.swift in Sources */,
Expand Down Expand Up @@ -796,7 +796,7 @@
A3C142542C8B381400D3CEC0 /* PayeeEditView.swift in Sources */,
920823F82CA498B500388AB2 /* CurrencyHistoryRepository.swift in Sources */,
A37E7D8A2C9AC30700B4ECFC /* HelpFAQView.swift in Sources */,
924353092CC4A2590052E4BC /* RepositoryLoadGroup.swift in Sources */,
924353092CC4A2590052E4BC /* RepositoryGroup.swift in Sources */,
924353152CC51F590052E4BC /* AssetViewModel.swift in Sources */,
924353052CC3B2E30052E4BC /* RepositoryViewModel.swift in Sources */,
924353212CC6EFA70052E4BC /* RepositoryLoadAux.swift in Sources */,
Expand Down
12 changes: 6 additions & 6 deletions MMEX/Theme/GroupTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ extension GroupTheme {
}
}

func manageItem<NameView: View>(
func manageItem<NameView: View, MainRepository: RepositoryProtocol>(
@ViewBuilder name nameView: @escaping () -> NameView,
count: RepositoryLoadState<Int>
count: RepositoryLoadMainCount<MainRepository>
) -> some View {
HStack {
nameView()
.font(.headline)
Spacer()
if showCount { switch count {
case .ready(let value):
BadgeCount(count: value)
if showCount { switch count.state {
case .ready:
BadgeCount(count: count.value)
case .loading:
ProgressView()
case .error(_):
case .error:
ProgressView().tint(.red)
case .idle:
EmptyView()
Expand Down
8 changes: 4 additions & 4 deletions MMEX/View/Account/AccountEditForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ struct AccountEditForm: View {
}

if
case let .ready(currencyOrder) = vm.currencyOrder.state,
case let .ready(currencyName) = vm.currencyName.state
vm.currencyOrder.state == .ready,
vm.currencyName.state == .ready
{
env.theme.field.picker(edit, "Currency") {
Picker("", selection: $data.currencyId) {
if (data.currencyId <= 0) {
Text("Select Currency").tag(0 as DataId) // not set
}
ForEach(currencyOrder, id: \.self) { id in
Text(currencyName[id] ?? "").tag(id)
ForEach(vm.currencyOrder.value, id: \.self) { id in
Text(vm.currencyName.value[id] ?? "").tag(id)
}
}
} show: {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Account/AccountReadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct AccountReadView: View {
data: $data,
edit: false
)
if case let .ready(used) = vm.accountUsed.state, !used.contains(data.id) {
if vm.accountUsed.state == .ready, !vm.accountUsed.value.contains(data.id) {
Button("Delete Account") {
let deleteError = vm.deleteAccount(data)
if deleteError != nil {
Expand Down
7 changes: 0 additions & 7 deletions MMEX/View/Insights/InsightsAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

import SwiftUI

struct InsightsAccountInfo {
var dataByType: [AccountType: [AccountData]] = [:]
var today: String = ""
var flowUntilToday: [DataId: AccountFlowByStatus] = [:]
var flowAfterToday: [DataId: AccountFlowByStatus] = [:]
}

struct InsightsAccountView: View {
@EnvironmentObject var env: EnvironmentManager
@ObservedObject var viewModel: InsightsViewModel
Expand Down
14 changes: 7 additions & 7 deletions MMEX/View/Manage/ManageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,43 @@ struct ManageView: View {
NavigationLink(destination: CurrencyListView()) {
env.theme.group.manageItem(
name: { Text(CurrencyData.dataName.1) },
count: vm.currencyCount.state
count: vm.currencyCount
)
}
NavigationLink(destination: AccountListView(vm: vm)) {
env.theme.group.manageItem(
name: { Text(AccountData.dataName.1) },
count: vm.accountCount.state
count: vm.accountCount
)
}
NavigationLink(destination: AssetListView()) {
env.theme.group.manageItem(
name: { Text(AssetData.dataName.1) },
count: vm.assetCount.state
count: vm.assetCount
)
}
NavigationLink(destination: StockListView()) {
env.theme.group.manageItem(
name: { Text(StockData.dataName.1) },
count: vm.stockCount.state
count: vm.stockCount
)
}
NavigationLink(destination: CategoryListView(viewModel: viewModel)) {
env.theme.group.manageItem(
name: { Text(CategoryData.dataName.1) },
count: vm.categoryCount.state
count: vm.categoryCount
)
}
NavigationLink(destination: PayeeListView()) {
env.theme.group.manageItem(
name: { Text(PayeeData.dataName.1) },
count: vm.payeeCount.state
count: vm.payeeCount
)
}
NavigationLink(destination: TransactionListView(viewModel: viewModel)) {
env.theme.group.manageItem(
name: { Text(TransactionData.dataName.1) },
count: vm.transactionCount.state
count: vm.transactionCount
)
}
}
Expand Down
Loading

0 comments on commit 6d42b66

Please sign in to comment.