Skip to content

Commit

Permalink
IncomeExpenses component
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Nov 6, 2023
1 parent 8eb873d commit 6121cf9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Header />
<div class="container">
<Balance :total="total" />
<IncomeExpenses />
<IncomeExpenses :income="+income" :expenses="+expenses" />
<TransactionList :transactions="transactions" />
<AddTransaction />
</div>
Expand Down Expand Up @@ -30,4 +30,20 @@ const total = computed(() => {
return acc + transaction.amount;
}, 0);
});
// Get income
const income = computed(() => {
return transactions.value
.filter((transaction) => transaction.amount > 0)
.reduce((acc, transaction) => acc + transaction.amount, 0)
.toFixed(2);
});
// Get expenses
const expenses = computed(() => {
return transactions.value
.filter((transaction) => transaction.amount < 0)
.reduce((acc, transaction) => acc + transaction.amount, 0)
.toFixed(2);
});
</script>
19 changes: 17 additions & 2 deletions src/components/IncomeExpenses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@
<div class="inc-exp-container">
<div>
<h4>Income</h4>
<p id="money-plus" class="money plus">+$0.00</p>
<p id="money-plus" class="money plus">+${{ income }}</p>
</div>
<div>
<h4>Expense</h4>
<p id="money-minus" class="money minus">-$0.00</p>
<p id="money-minus" class="money minus">-${{ expenses }}</p>
</div>
</div>
</template>

<script setup>
import { defineProps } from 'vue';
const props = defineProps({
income: {
type: Number,
required: true,
},
expenses: {
type: Number,
required: true,
},
});
</script>

0 comments on commit 6121cf9

Please sign in to comment.