diff --git a/islands/BudgetCard.tsx b/islands/BudgetCard.tsx index b6e78cf..a89e377 100644 --- a/islands/BudgetCard.tsx +++ b/islands/BudgetCard.tsx @@ -3,6 +3,7 @@ import { Budget } from '../models.ts' import { Currency } from '../components/Currency.tsx' import { Percentage } from '../components/Percentage.tsx' import { Component } from 'https://esm.sh/stable/preact@10.19.6/denonext/preact.mjs' +import { truncate } from '../mod.ts' function BudgetCardLit( { budget, ...props }: @@ -69,20 +70,21 @@ export function BudgetCard( & { budget: Budget } & JSX.HTMLAttributes, ) { - const remainingRatio = 1.0 - (budget.spent / budget.target) - const bgClass = (remainingRatio < 0 ? 'bg-red' : 'bg-green') + ' opacity-10' + const spentRatio = budget.spent / budget.target + const remainingRatio = 1.0 - spentRatio + const bgClass = (spentRatio > 1.0 ? 'bg-red' : 'bg-green') + ' opacity-10' const accentTextClass = remainingRatio < 0 ? 'text-red' : 'text-green' return ( - {remainingRatio >= 0 ? ` left ` : ` over `} + {spentRatio >= 0 ? ` left ` : ` over `} } {...props} @@ -91,7 +93,7 @@ export function BudgetCard( of{' '} {' spent '} - ( remaining) + ( remaining) ) @@ -102,13 +104,22 @@ interface ProgressBarCardProps { subheading: JSX.Element bgClass: string accentTextClass: string - ratio: number + fillRatio: number } export function ProgressBarCard( - { heading, subheading, bgClass, accentTextClass, ratio, children, ...props }: + { + heading, + subheading, + bgClass, + accentTextClass, + fillRatio, + children, + ...props + }: & ProgressBarCardProps & JSX.HTMLAttributes, ) { + console.log({ fillRatio }) return (

@@ -102,6 +105,21 @@ export default function Dashboard() {
{/*

Budgets Overview

*/}
+ {uncategorizedSpend <= 0 ? '' : ( + + + + } + > + You should categorize these! + + )} {budgets.map((budget, _i) => )}
diff --git a/mod.ts b/mod.ts index b31559d..2dcffc3 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,7 @@ -console.log('Hello, world!') - -if (true) { - console.log('Truth!') +export function truncate(s: string, len: number): string { + if (s.length >= len) { + return s.substring(0, len - 3) + '...' + } else { + return s + } }