diff --git a/src/store/index.js b/src/store/index.js index 521e6a44..7f5565e0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -18,6 +18,7 @@ import { UPDATE_ACCOUNT_LIST_INVALID_STATE, LOAD_TRANSACTION_LIST, + COLLAPSE_MONTH_IN_TRANSACTION_LIST, SAVE_TRANSACTION_IN_TRANSACTION_LIST, REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, UPDATE_TRANSACTION_LIST_INVALID_STATE, @@ -343,6 +344,11 @@ const stores = { state.transactionsNextTimeId = -1; } }, + [COLLAPSE_MONTH_IN_TRANSACTION_LIST] (state, { month, collapse }) { + if (month) { + month.opened = !collapse; + } + }, [SAVE_TRANSACTION_IN_TRANSACTION_LIST] (state, { transaction, defaultCurrency, accountId }) { for (let i = 0; i < state.transactions.length; i++) { const transactionMonthList = state.transactions[i]; @@ -581,6 +587,7 @@ const stores = { getTransaction: transaction.getTransaction, saveTransaction: transaction.saveTransaction, deleteTransaction: transaction.deleteTransaction, + collapseMonthInTransactionList: transaction.collapseMonthInTransactionList, loadAllCategories: transactionCategory.loadAllCategories, getCategory: transactionCategory.getCategory, diff --git a/src/store/mutations.js b/src/store/mutations.js index 0759881e..94658c2c 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -14,6 +14,7 @@ export const REMOVE_ACCOUNT_FROM_ACCOUNT_LIST = 'REMOVE_ACCOUNT_FROM_ACCOUNT_LIS export const UPDATE_ACCOUNT_LIST_INVALID_STATE = 'UPDATE_ACCOUNT_LIST_INVALID_STATE'; export const LOAD_TRANSACTION_LIST = 'LOAD_TRANSACTION_LIST'; +export const COLLAPSE_MONTH_IN_TRANSACTION_LIST = 'COLLAPSE_MONTH_IN_TRANSACTION_LIST'; export const SAVE_TRANSACTION_IN_TRANSACTION_LIST = 'SAVE_TRANSACTION_IN_TRANSACTION_LIST'; export const REMOVE_TRANSACTION_FROM_TRANSACTION_LIST = 'REMOVE_TRANSACTION_FROM_TRANSACTION_LIST'; export const UPDATE_TRANSACTION_LIST_INVALID_STATE = 'UPDATE_TRANSACTION_LIST_INVALID_STATE'; diff --git a/src/store/transaction.js b/src/store/transaction.js index 25cd808e..ba955b30 100644 --- a/src/store/transaction.js +++ b/src/store/transaction.js @@ -6,16 +6,22 @@ import utils from '../lib/utils.js'; import { LOAD_TRANSACTION_LIST, + COLLAPSE_MONTH_IN_TRANSACTION_LIST, REMOVE_TRANSACTION_FROM_TRANSACTION_LIST, UPDATE_TRANSACTION_LIST_INVALID_STATE, UPDATE_ACCOUNT_LIST_INVALID_STATE, } from './mutations.js'; +const emptyTransactionResult = { + items: [], + transactionsNextTimeId: 0 +}; + function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime, minTime, type, categoryId, accountId, keyword }) { let actualMaxTime = context.state.transactionsNextTimeId; if (reload && maxTime > 0) { - actualMaxTime = maxTime * 1000 + 999; + actualMaxTime = maxTime; } else if (reload && maxTime <= 0) { actualMaxTime = 0; } @@ -32,6 +38,17 @@ function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime const data = response.data; if (!data || !data.success || !data.result) { + if (reload) { + context.commit(LOAD_TRANSACTION_LIST, { + transactions: emptyTransactionResult, + reload: reload, + autoExpand: autoExpand, + defaultCurrency: defaultCurrency, + accountId: accountId + }); + context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); + } + reject({ message: 'Unable to get transaction list' }); return; } @@ -52,6 +69,17 @@ function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime }).catch(error => { logger.error('failed to load transaction list', error); + if (reload) { + context.commit(LOAD_TRANSACTION_LIST, { + transactions: emptyTransactionResult, + reload: reload, + autoExpand: autoExpand, + defaultCurrency: defaultCurrency, + accountId: accountId + }); + context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true); + } + if (error.response && error.response.data && error.response.data.errorMessage) { reject({ error: error.response.data }); } else if (!error.processed) { @@ -184,6 +212,13 @@ function deleteTransaction(context, { transaction, defaultCurrency, accountId, b }); } +function collapseMonthInTransactionList(context, { month, collapse }) { + context.commit(COLLAPSE_MONTH_IN_TRANSACTION_LIST, { + month: month, + collapse: collapse + }); +} + function noTransaction(state) { for (let i = 0; i < state.transactions.length; i++) { const transactionMonthList = state.transactions[i]; @@ -263,6 +298,7 @@ export default { getTransaction, saveTransaction, deleteTransaction, + collapseMonthInTransactionList, noTransaction, hasMoreTransaction, calculateMonthTotalAmount diff --git a/src/views/mobile/transactions/List.vue b/src/views/mobile/transactions/List.vue index 8b77b2f1..20c956a3 100644 --- a/src/views/mobile/transactions/List.vue +++ b/src/views/mobile/transactions/List.vue @@ -132,8 +132,8 @@ + @accordion:open="collapseTransactionMonthList(transactionMonthList, false)" + @accordion:close="collapseTransactionMonthList(transactionMonthList, true)"> @@ -521,6 +521,12 @@ export default { } }); }, + collapseTransactionMonthList(month, collapse) { + this.$store.dispatch('collapseMonthInTransactionList', { + month: month, + collapse: collapse + }); + }, changeDateFilter(dateType) { if (dateType === 11) { // Custom this.showCustomDateRangeSheet = true; @@ -567,7 +573,6 @@ export default { return; } - this.transactions = []; this.query.dateType = dateType; this.showDatePopover = false; @@ -581,7 +586,6 @@ export default { this.query.maxTime = maxTime; this.query.minTime = minTime; - this.transactions = []; this.query.dateType = 11; this.showCustomDateRangeSheet = false; @@ -601,7 +605,6 @@ export default { } } - this.transactions = []; this.query.type = type; this.showTypePopover = false; this.reload(null); @@ -611,7 +614,6 @@ export default { return; } - this.transactions = []; this.query.categoryId = categoryId; this.showCategoryPopover = false; this.reload(null); @@ -621,7 +623,6 @@ export default { return; } - this.transactions = []; this.query.accountId = accountId; this.showAccountPopover = false; this.reload(null); @@ -631,7 +632,6 @@ export default { return; } - this.transactions = []; this.query.keyword = keyword; this.reload(null); },