Skip to content

Commit

Permalink
Delete transaction (DOM Only)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Nov 6, 2023
1 parent 1749a06 commit babc9c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<div class="container">
<Balance :total="total" />
<IncomeExpenses :income="+income" :expenses="+expenses" />
<TransactionList :transactions="transactions" />
<TransactionList
:transactions="transactions"
@transactionDeleted="handleTransactionDeleted"
/>
<AddTransaction @transactionSubmitted="handleTransactionSubmitted" />
</div>
</template>
Expand Down Expand Up @@ -66,4 +69,13 @@ const handleTransactionSubmitted = (transactionData) => {
const generateUniqueId = () => {
return Math.floor(Math.random() * 1000000);
};
// Delete transaction
const handleTransactionDeleted = (id) => {
transactions.value = transactions.value.filter(
(transaction) => transaction.id !== id
);
toast.success('Transaction deleted.');
};
</script>
10 changes: 9 additions & 1 deletion src/components/TransactionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
:class="transaction.amount < 0 ? 'minus' : 'plus'"
>
{{ transaction.text }} <span>${{ transaction.amount }}</span
><button class="delete-btn">x</button>
><button class="delete-btn" @click="deleteTransaction(transaction.id)">
x
</button>
</li>
</ul>
</template>
Expand All @@ -21,4 +23,10 @@ const props = defineProps({
required: true,
},
});
const emit = defineEmits(['transactionDeleted']);
const deleteTransaction = (id) => {
emit('transactionDeleted', id);
};
</script>

0 comments on commit babc9c6

Please sign in to comment.