From 52501b0201180bf6f6c4834da276841c536f167e Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Thu, 23 May 2019 19:14:38 +0100 Subject: [PATCH] Initiated slots, props and emitting on the modal for a better procedural process. --- src/components/ApplyTag.vue | 27 +++++++++++++------------- src/views/Home.vue | 38 +++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/components/ApplyTag.vue b/src/components/ApplyTag.vue index d84abaa..5f0769a 100644 --- a/src/components/ApplyTag.vue +++ b/src/components/ApplyTag.vue @@ -1,17 +1,14 @@ @@ -20,22 +17,24 @@ export default { name: 'app', + props: [ + "transaction", + "isModalVisible" + ], components: { Modal, }, data () { return { - isModalVisible: false, }; }, methods: { showModal() { - this.isModalVisible = true; + this.$emit('show'); }, closeModal() { - this.isModalVisible = false; + this.$emit('close'); } }, }; - - + \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index cbfdbef..9814715 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,7 +1,7 @@ @@ -26,6 +26,8 @@ export default { "bank": "" } ], + isModalVisible: false, + newTransaction: {}, "transactions": [], tagsExpenditure: [ "Appearance", @@ -65,28 +67,36 @@ export default { this.transactions = this.transactions.filter(transaction => transaction.id !== id); localStorage.setItem("transactionStorage", JSON.stringify(this.transactions)); }, - addTransaction(newTransaction) { + addTransaction() { + // When the confirmation button is clicked, return the value of the dropdown + + + // Add the transaction + this.transactions.push(this.newTransaction); + this.saveTransactions(); + }, + checkTransactionExists(newTransaction) { // Determine whether this transaction already exists const found = this.transactions.some(transaction => transaction.date === newTransaction.date && transaction.transactionTypeDescription === newTransaction.transactionTypeDescription && transaction.description === newTransaction.description && transaction.isExpenditure === newTransaction.isExpenditure && transaction.amount === newTransaction.amount && transaction.balance === newTransaction.balance); if (found) { alert('found duplicate transaction, not adding it - ' + newTransaction.date + ' :: ' + newTransaction.description); } else { - // Open a modal to let the user select a tag to apply to the transaction - // var newTransactionWithTag = this.applyTag(newTransaction); - - // Add the transaction - this.transactions.push(newTransaction); - this.saveTransactions(); + // Store the transaction in the Vue data + this.newTransaction = newTransaction; + // Open the modal & display the transaction along with a dropdown of transaction tags and a confirmation button to let the user select a tag to apply to the transaction + this.isModalVisible = true; } }, - // applyTag(newTransaction) { - - // }, saveTransactions() { - localStorage.setItem("lastname", "Smith"); localStorage.setItem("transactionStorage", JSON.stringify(this.transactions)); - } + }, + closeModal() { + this.isModalVisible = false; + }, + showModal() { + this.isModalVisible = true; + }, } }