From a787abdbc0b949b048b541ca47e4abc1f907b500 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 27 Jan 2021 02:40:47 +0100 Subject: [PATCH] Improved Transaction design and function --- .vscode/settings.json | 3 +- .../balance/components/Transaction.vue | 101 ++++++++++++------ src/plugins/balance/pages/Add.vue | 20 +--- src/plugins/balance/pages/Transfer.vue | 16 +-- 4 files changed, 77 insertions(+), 63 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 89e30df..ae2ea04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,5 +24,6 @@ "sortAttributes": false } }, - "vetur.format.defaultFormatter.ts": "prettier-tslint" + "vetur.format.defaultFormatter.ts": "prettier-tslint", + "typescript.format.enable": false } diff --git a/src/plugins/balance/components/Transaction.vue b/src/plugins/balance/components/Transaction.vue index 5e51920..e64cd31 100644 --- a/src/plugins/balance/components/Transaction.vue +++ b/src/plugins/balance/components/Transaction.vue @@ -1,24 +1,33 @@ diff --git a/src/plugins/balance/pages/Add.vue b/src/plugins/balance/pages/Add.vue index 1a179a1..19706e1 100644 --- a/src/plugins/balance/pages/Add.vue +++ b/src/plugins/balance/pages/Add.vue @@ -56,8 +56,9 @@ -
- +
+ +
@@ -80,7 +81,7 @@ export default defineComponent({ const amount = ref(0); const showAddShortcut = ref(false); - const transactions = ref([]); + const transactions = computed(() => store.state.balance.transactions.slice().reverse()); const user = ref(store.state.user.currentUser); const shortCuts = ref(store.state.balance.shortcuts); @@ -89,7 +90,7 @@ export default defineComponent({ ); function addShortcut() { - void store.dispatch('balance/addShortcut', amount.value * -1); + if (amount.value != 0) void store.dispatch('balance/addShortcut', amount.value * -1); } function removeShortcut(shortcut: number) { void store.dispatch('balance/removeShortcut', shortcut); @@ -100,19 +101,9 @@ export default defineComponent({ function changeBalance(amount: number) { store .dispatch('balance/changeBalance', { amount: amount, user: user.value?.userid }) - .then((transaction: FG.Transaction) => { - if (transactions.value.length > 5) transactions.value.pop(); - transaction.time = new Date(transaction.time); - transactions.value.unshift(transaction); - console.log(transactions.value); - }) .catch(err => console.log(err)); } - function reversed(id: number) { - transactions.value = transactions.value.filter(t => t.id != id); - } - return { user, addShortcut, @@ -123,7 +114,6 @@ export default defineComponent({ amount, showSelector, shortCuts, - reversed, userUpdated }; } diff --git a/src/plugins/balance/pages/Transfer.vue b/src/plugins/balance/pages/Transfer.vue index 83a7f0e..eaa021f 100644 --- a/src/plugins/balance/pages/Transfer.vue +++ b/src/plugins/balance/pages/Transfer.vue @@ -31,7 +31,7 @@
- +
@@ -56,7 +56,7 @@ export default defineComponent({ const sender = ref(store.state.user.currentUser); const receiver = ref(undefined); const amount = ref(0); - const transactions = ref([]); + const transactions = computed(() => store.state.balance.transactions.slice().reverse()); const sendDisabled = computed(() => { return !( @@ -75,10 +75,6 @@ export default defineComponent({ receiver.value = selectedUser; } - function reversed(id: number) { - transactions.value = transactions.value.filter(value => value.id != id); - } - function sendAmount() { store .dispatch('balance/changeBalance', { @@ -86,11 +82,6 @@ export default defineComponent({ sender: sender.value?.userid, user: receiver.value?.userid }) - .then((transaction: FG.Transaction) => { - if (transactions.value.length > 5) transactions.value.pop(); - transaction.time = new Date(transaction.time); - transactions.value.unshift(transaction); - }) .catch(err => console.log(err)); } @@ -103,8 +94,7 @@ export default defineComponent({ showSelector, senderUpdated, receiverUpdated, - sendDisabled, - reversed + sendDisabled }; } });