|
1 | 1 | import { ToastManager } from "./managers/toast"; |
2 | 2 | const toastManager = new ToastManager(document.getElementById('toast-container')); |
3 | 3 |
|
| 4 | +// Global variables |
| 5 | +let currentTransactionType = 'income'; // Default transaction type |
| 6 | +let currentFilter = null; // null = show all, 'income' = only income, 'expense' = only expenses |
| 7 | +let editingTransactionId = null; |
| 8 | +let currentSortField = 'date'; |
| 9 | +let currentSortDirection = 'desc'; |
| 10 | + |
4 | 11 | // Theme toggle functionality |
5 | 12 | function getBaseUrl() { |
6 | 13 | // First try to get it from the server-provided meta tag |
@@ -314,16 +321,6 @@ async function handleFetchResponse(response) { |
314 | 321 | return response; |
315 | 322 | } |
316 | 323 |
|
317 | | -// Add currentFilter variable at the top with other shared variables |
318 | | -let currentFilter = null; // null = show all, 'income' = only income, 'expense' = only expenses |
319 | | - |
320 | | -// Add at the top with other variables |
321 | | -let editingTransactionId = null; |
322 | | - |
323 | | -// Add at the top with other shared variables |
324 | | -let currentSortField = 'date'; |
325 | | -let currentSortDirection = 'desc'; |
326 | | - |
327 | 324 | // Update loadTransactions function |
328 | 325 | async function loadTransactions() { |
329 | 326 | try { |
@@ -470,6 +467,9 @@ function editTransaction(id, transaction, isRecurringInstance) { |
470 | 467 | document.getElementById('description').value = transaction.description; |
471 | 468 | document.getElementById('transactionDate').value = transaction.date; |
472 | 469 |
|
| 470 | + // Update the currentTransactionType to match the transaction being edited |
| 471 | + currentTransactionType = transaction.type; |
| 472 | + |
473 | 473 | // Set transaction type |
474 | 474 | toggleBtns.forEach(btn => { |
475 | 475 | btn.classList.toggle('active', btn.dataset.type === transaction.type); |
@@ -651,8 +651,6 @@ function initModalHandling() { |
651 | 651 | const toggleBtns = document.querySelectorAll('.toggle-btn'); |
652 | 652 | const amountInput = document.getElementById('amount'); |
653 | 653 |
|
654 | | - let currentTransactionType = 'income'; |
655 | | - |
656 | 654 | // Initialize category handling |
657 | 655 | initCategoryHandling(); |
658 | 656 |
|
|
0 commit comments