From 44b50edf8281faeb943ed0509bab8291a8f59b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 30 Jan 2021 11:23:18 +0100 Subject: [PATCH] [balance] fixed transactions exists only once in store change icons in circular progress --- src/components/loading/CircularProgress.vue | 2 +- .../loading/DarkCircularProgress.vue | 2 +- src/plugins/balance/pages/MainPage.vue | 19 ++++++++----- src/plugins/balance/store/balance.ts | 28 +++++++++++-------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/components/loading/CircularProgress.vue b/src/components/loading/CircularProgress.vue index b59b9d9..3f3f113 100644 --- a/src/components/loading/CircularProgress.vue +++ b/src/components/loading/CircularProgress.vue @@ -10,7 +10,7 @@ track-color="grey-3" > - + diff --git a/src/components/loading/DarkCircularProgress.vue b/src/components/loading/DarkCircularProgress.vue index 2be058e..6eec95d 100644 --- a/src/components/loading/DarkCircularProgress.vue +++ b/src/components/loading/DarkCircularProgress.vue @@ -10,7 +10,7 @@ track-color="grey-3" > - + diff --git a/src/plugins/balance/pages/MainPage.vue b/src/plugins/balance/pages/MainPage.vue index 0c9bbcd..acab96f 100644 --- a/src/plugins/balance/pages/MainPage.vue +++ b/src/plugins/balance/pages/MainPage.vue @@ -42,10 +42,10 @@ animated > - + - + @@ -70,13 +70,17 @@ export default defineComponent({ const store = >root.$store; const now = new Date() onMounted(() => { - void store.dispatch('balance/getTransactions', {filter: {from: new Date(now.getFullYear(), now.getMonth(), now.getDay())}}) + void store.dispatch('balance/getTransactions', {filter: {from: new Date(now.getFullYear(), now.getMonth(), now.getDate())}}) }) const transactions = computed(() => - store.state.balance.transactions + { + const a =store.state.balance.transactions .filter(t => t.original_id == undefined) + .filter(t => t.time > new Date(now.getFullYear(), now.getMonth(), now.getDate())) .sort((a, b) => (a.time >= b.time ? -1 : 1)) - ); + console.log(a) + return a + }); const canAdd = () => hasSomePermissions([PERMISSIONS.DEBIT, PERMISSIONS.CREDIT, PERMISSIONS.DEBIT_OWN], store); @@ -95,7 +99,7 @@ export default defineComponent({ const drawer = ref(false); - const showDrawer = computed({ +/* const showDrawer = computed({ get: () => { return !Screen.gt.sm && drawer.value; }, @@ -103,7 +107,8 @@ export default defineComponent({ drawer.value = val; } }); - +*/ + const showDrawer = ref(false); const tab = ref(canAdd() ? 'add' : 'transfer'); const show = ref(false); return { diff --git a/src/plugins/balance/store/balance.ts b/src/plugins/balance/store/balance.ts index 8199296..797a1b0 100644 --- a/src/plugins/balance/store/balance.ts +++ b/src/plugins/balance/store/balance.ts @@ -37,7 +37,7 @@ const state: BalanceInterface = { balances: new Map(), shortcuts: [], transactions: [], - loading: 0 + loading: 0, }; function fixTransaction(t: FG.Transaction) { @@ -73,15 +73,19 @@ const mutations: MutationTree = { state.transactions.push(data); }, addTransactions(state, data: [FG.Transaction]) { - state.transactions.push(...data); + data.forEach((transaction) => { + if (!state.transactions.find((t) => t.id == transaction.id)) { + state.transactions.push(transaction); + } + }); state.transactions.sort((a, b) => (a.time <= b.time ? -1 : 1)); }, reverseTransaction(state, data: { transaction: FG.Transaction; reversal: FG.Transaction }) { - const idx = state.transactions.findIndex(value => value.id === data.transaction.id); + const idx = state.transactions.findIndex((value) => value.id === data.transaction.id); data.transaction.reversal_id = data.reversal.id; if (idx > -1) state.transactions[idx] = data.transaction; else state.transactions.push(data.transaction); - } + }, }; const actions: ActionTree = { @@ -151,7 +155,7 @@ const actions: ActionTree = { return axios .get(`/users/${payload.userid}/balance/transactions`, { params: payload.filter || {} }) .then(({ data }: AxiosResponse) => { - data.transactions.forEach(t => fixTransaction(t)); + data.transactions.forEach((t) => fixTransaction(t)); commit('addTransactions', data.transactions); return data; }) @@ -165,7 +169,7 @@ const actions: ActionTree = { .then(({ data }) => { console.log(data); }) - .catch(err => { + .catch((err) => { console.warn(err); }) .finally(() => commit('setLoading', false)); @@ -176,7 +180,7 @@ const actions: ActionTree = { .then(({ data }: AxiosResponse) => { fixTransaction(data); commit('reverseTransaction', { transaction: transaction, reversal: data }); - dispatch('getBalance').catch(err => console.warn(err)); + dispatch('getBalance').catch((err) => console.warn(err)); }); }, changeBalance( @@ -196,23 +200,23 @@ const actions: ActionTree = { commit('addTransaction', transaction); commit(state.balances.has(data.user) ? 'changeBalance' : 'setBalance', { userid: data.user, - amount: data.amount + amount: data.amount, }); if (data.sender) commit(state.balances.has(data.sender) ? 'changeBalance' : 'setBalance', { userid: data.sender, - amount: -1 * data.amount + amount: -1 * data.amount, }); return transaction; }) - .catch(err => { + .catch((err) => { console.debug(err); // Maybe Balance changed void dispatch('getTransactions', {}); return dispatch('getBalance', data.sender ? data.sender : data.user); }) .finally(() => commit('setLoading', false)); - } + }, }; const getters: GetterTree = {}; @@ -222,7 +226,7 @@ const balance: Module = { state, mutations, actions, - getters + getters, }; export default balance;