Skip to content

Commit

Permalink
Merge pull request #49 from evmiguel/initial-analysis-cost
Browse files Browse the repository at this point in the history
Adding cost to list of items bought
  • Loading branch information
evmiguel authored Apr 9, 2024
2 parents 0847187 + 02a0c44 commit 3d6930c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/Analysis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function Analysis({ purchases }: AnalysisProps) {

const filteredPurchases = filterPurchases(purchases, context.purchaseFilter);

const itemsBought = filteredPurchases.filter((value, index, self) => index === self.findIndex((p) => p.name === value.name));
const itemsBought = sumByKey(filteredPurchases, 'name', 'cost').sort((a, b) => b.cost - a.cost);

const categoriesChartData = sumByKey(filteredPurchases.map(purchase => {
return { name: purchase.category, value: 1}
Expand Down Expand Up @@ -154,7 +154,10 @@ export default function Analysis({ purchases }: AnalysisProps) {
<TabsContent value="items">
<ul>
{itemsBought.map(purchase => (
<li key={purchase.id}>{purchase.name}</li>
<li className="flex justify-between" key={purchase.name}><span className="inline-block">{purchase.name}</span> <span className="inline-block">{new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(purchase.cost)}</span></li>
))}
</ul>
</TabsContent>
Expand Down

0 comments on commit 3d6930c

Please sign in to comment.