From 3928caff0cec2e24a8b9bff9ff0e4269d47ae7b1 Mon Sep 17 00:00:00 2001 From: Lisheng Guan Date: Fri, 27 Sep 2024 11:01:27 +0800 Subject: [PATCH 1/2] Refine Txn edit to better use available space --- MMEX/Views/Transactions/TransactionEditView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MMEX/Views/Transactions/TransactionEditView.swift b/MMEX/Views/Transactions/TransactionEditView.swift index 0acea8b..3ef6f57 100644 --- a/MMEX/Views/Transactions/TransactionEditView.swift +++ b/MMEX/Views/Transactions/TransactionEditView.swift @@ -33,7 +33,6 @@ struct TransactionEditView: View { } } .pickerStyle(SegmentedPickerStyle()) // Use a segmented style for the picker - .padding(.horizontal) Spacer() @@ -45,11 +44,12 @@ struct TransactionEditView: View { Text(account.data.name).tag(account.data.id) } } + .frame(maxWidth: .infinity) // Allow picker to use available space } - .padding(.horizontal) + .padding(.horizontal, 0) // 2. Unified Numeric Input for the Amount with automatic keyboard focus - TextField("¥0", text: $amountString) + TextField("0", text: $amountString) .keyboardType(.decimalPad) // Show numeric keyboard with decimal support .font(.system(size: 48, weight: .bold)) // Large, bold text for amount input .multilineTextAlignment(.center) // Center the text for better UX @@ -101,7 +101,7 @@ struct TransactionEditView: View { } } } - .padding(.horizontal) + .padding(.horizontal, 0) // 5. Horizontal stack for Payee and Category pickers HStack { @@ -132,7 +132,7 @@ struct TransactionEditView: View { } .pickerStyle(MenuPickerStyle()) // Show a menu for the category picker } - .padding(.horizontal) + .padding(.horizontal, 0) Spacer() // Push the contents to the top } From 73cf6413edace408c295b841ffa117e7ea3bbd4d Mon Sep 17 00:00:00 2001 From: Lisheng Guan Date: Fri, 27 Sep 2024 11:10:06 +0800 Subject: [PATCH 2/2] Refine Txn edit to make payee & category as mandatory --- MMEX/Views/Transactions/TransactionAddView.swift | 4 ++++ MMEX/Views/Transactions/TransactionAddView2.swift | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/MMEX/Views/Transactions/TransactionAddView.swift b/MMEX/Views/Transactions/TransactionAddView.swift index 4be3818..fd7c5a5 100644 --- a/MMEX/Views/Transactions/TransactionAddView.swift +++ b/MMEX/Views/Transactions/TransactionAddView.swift @@ -31,10 +31,14 @@ struct TransactionAddView: View { isPresentingTransactionAddView = false onSave(&newTxn) } + .disabled(!isTransactionValid()) } } } } + func isTransactionValid() -> Bool { + return newTxn.payeeId > 0 && newTxn.categId > 0 + } } #Preview { diff --git a/MMEX/Views/Transactions/TransactionAddView2.swift b/MMEX/Views/Transactions/TransactionAddView2.swift index 98466bb..2612dce 100644 --- a/MMEX/Views/Transactions/TransactionAddView2.swift +++ b/MMEX/Views/Transactions/TransactionAddView2.swift @@ -37,6 +37,7 @@ struct TransactionAddView2: View { selectedTab = 0 newTxn = TransactionData() } + .disabled(!isTransactionValid()) } } } @@ -57,6 +58,10 @@ struct TransactionAddView2: View { } } + func isTransactionValid() -> Bool { + return newTxn.payeeId > 0 && newTxn.categId > 0 + } + func addTransaction(txn: inout TransactionData) { let repository = dataManager.getTransactionRepository() if repository.insert(&txn) {