diff --git a/src/app/(app)/page.tsx b/src/app/(app)/page.tsx index 78f9521..ce29562 100644 --- a/src/app/(app)/page.tsx +++ b/src/app/(app)/page.tsx @@ -1,6 +1,8 @@ -import { ChevronRight } from "lucide-react"; +import { Check, ChevronRight } from "lucide-react"; import Link from "next/link"; import { Suspense } from "react"; +import { Amount, CountUp, HideMoney } from "@/components/Amount"; +import { CashChart } from "@/components/CashChart"; import { CategoryCheck, type Checks } from "@/components/CategoryCheck"; import { CountryBanner } from "@/components/CountryPicker"; import { EmptyBank } from "@/components/EmptyBank"; @@ -11,8 +13,9 @@ import { PayQuestion } from "@/components/PayQuestion"; import { SyncButton } from "@/components/PlaidButtons"; import { TxnList } from "@/components/TxnList"; import { WeekCard } from "@/components/WeekCard"; -import { categories, getUser, moneyByMonth, today, TXN_SELECT, withAccountNames, type Txn } from "@/lib/data"; -import { dateLabel, money0, monthStart, ymd } from "@/lib/format"; +import { accountName, categories, getUser, isIncome, isSpend, moneyByMonth, today, transactionsSince, TXN_SELECT, withAccountNames, type Txn } from "@/lib/data"; +import { dateLabel, money, money0, monthStart, ymd } from "@/lib/format"; +import { addDays, cashSeries, flows, forecast, relDay, weekVsUsual } from "@/lib/home"; import { deterministicMoves, ladder } from "@/lib/plan"; import { myPlanFacts } from "@/lib/plan-facts"; import { payGuess } from "@/lib/pay"; @@ -57,113 +60,189 @@ async function NextStep({ profile }: { profile: Record }) { ); } -// Home is for a glance: what you have, what went out this month, what's coming up, what you spent last. -// The working pages (Spending, Budgets, Money plan) are one click away. +const ago = (iso: string | null) => { + if (!iso) return null; + const m = Math.round((Date.now() - Date.parse(iso)) / 60e3); + return m < 1 ? "just now" : m < 60 ? `${m} min ago` : m < 48 * 60 ? `${Math.round(m / 60)} h ago` : `${Math.round(m / 1440)} days ago`; +}; + +type Item = { institution_name: string | null; institution_logo: string | null; institution_color: string | null; last_synced_at: string | null } | null; +type Acct = { id: string; name: string; custom_name: string | null; mask: string | null; type: string; subtype: string | null; current_balance: number | null; included: boolean; item: Item }; +type Stream = { id: string; merchant_name: string; logo_url: string | null; average_amount: number; last_date: string | null; next_date: string | null; is_income: boolean }; + +// Home is for a glance: cash and where it's heading, the accounts, what went out this month, the bills, the latest spending. +// The working pages (Spending, Budgets, Money plan) are one click away. Two-card rows stretch to one height (Max, 2026-11-10). export default async function Dashboard() { const { supabase, user } = await getUser(); const uid = user!.id; const profile = user?.user_metadata?.profile; const now = await today(); // the user's date at UTC midnight: read it with getUTC* and ymd - const day = ymd(now), soon = ymd(new Date(now.getTime() + 14 * 864e5)); + const day = ymd(now), month = day.slice(0, 7); const checks = (fetchChecks(supabase, uid, day) as Promise).catch(() => ({ rows: [], total: 0 })); // starts now, beside the queries below // Own rows only: an account a partner shares is on the Accounts page, not in your totals. - const [{ data: recent }, { data: accounts }, { data: noRate }, { data: bills }, rows, cats] = await Promise.all([ - supabase.from("transactions").select(TXN_SELECT).eq("user_id", uid).order("date", { ascending: false }).order("id").limit(5), - supabase.from("accounts").select("type, subtype, current_balance:home_balance, included").eq("user_id", uid), + const [{ data: recent }, { data: accounts }, { data: noRate }, { data: streams }, { data: first }, rows, cats, last62] = await Promise.all([ + supabase.from("transactions").select(TXN_SELECT).eq("user_id", uid).order("date", { ascending: false }).order("id").limit(12), + supabase.from("accounts").select("id, name, custom_name, mask, type, subtype, current_balance:home_balance, included, item:plaid_items(institution_name, institution_logo, institution_color, last_synced_at)").eq("user_id", uid), supabase.rpc("fx_missing"), - supabase.from("recurring").select("id, merchant_name, logo_url, average_amount:home_average, next_date").eq("user_id", uid).eq("active", true).eq("is_income", false).neq("status", "TOMBSTONED").gte("next_date", day).lte("next_date", soon).order("next_date").limit(4), + supabase.from("recurring").select("id, merchant_name, logo_url, average_amount:home_average, last_date, next_date, is_income").eq("user_id", uid).eq("active", true).neq("status", "TOMBSTONED"), + supabase.from("transactions").select("date").eq("user_id", uid).order("date").limit(1), moneyByMonth(supabase, ymd(monthStart(now))), categories(), + transactionsSince(addDays(day, -62)), ]); if (!accounts?.length) return ; + const accts = accounts as unknown as Acct[]; + const sum = (list: Acct[]) => list.reduce((s, a) => s + Number(a.current_balance ?? 0), 0); + const cashAccts = accts.filter((a) => a.included && a.type === "depository" && a.subtype !== "savings"); + const cashIds = new Set(cashAccts.map((a) => a.id)); + const cash = sum(cashAccts); + const debts = accts.filter((a) => a.included && (a.type === "credit" || a.type === "loan")); + const owed = Math.abs(sum(debts)); + const assets = sum(accts.filter((a) => a.included && !debts.includes(a))); + const synced = accts.map((a) => a.item?.last_synced_at).filter((x): x is string => !!x).sort().at(-1) ?? null; + const banks = new Set(accts.map((a) => a.item?.institution_name).filter(Boolean)); + + // The cash line: today's cash balance walked back through what moved those accounts. Forecast: bills before payday, then pay. + const series = cashSeries(cash, last62.filter((t) => t.account && cashIds.has(t.account.id)).map((t) => ({ date: t.date, amount: Number(t.amount) })), day, 31); + const all = (streams ?? []) as unknown as Stream[]; + const pay = all.filter((s) => s.is_income && s.next_date && s.next_date > day).sort((a, b) => a.next_date!.localeCompare(b.next_date!))[0]; + const bills = all.filter((s) => !s.is_income); + const fc = cashAccts.length ? forecast(cash, day, bills.filter((b) => b.next_date).map((b) => ({ date: b.next_date!, amount: Math.abs(Number(b.average_amount)) })), pay ? { date: pay.next_date!, amount: Math.abs(Number(pay.average_amount)) } : null) : null; + const moneyRows = last62.filter((t) => isSpend(t) || isIncome(t)).map((t) => ({ date: t.date, amount: Number(t.amount) })); + const flowsBy = { 7: flows(moneyRows, day, 7), 31: flows(moneyRows, day, 31) }; + const week = weekVsUsual(last62.filter(isSpend).map((t) => ({ date: t.date, amount: Number(t.amount) })), day, (first?.[0]?.date as string | undefined) ?? null); + const under = week ? week.thisWeek <= week.usual : true; + + // Bills this month: the ones already paid (ticked, faded), then the ones still to come. + const paid = bills.filter((b) => b.last_date?.startsWith(month) && b.last_date <= day).sort((a, b) => a.last_date!.localeCompare(b.last_date!)); + const due = bills.filter((b) => b.next_date?.startsWith(month) && b.next_date >= day && !paid.includes(b)).sort((a, b) => a.next_date!.localeCompare(b.next_date!)); + const monthBills = [...paid.map((b) => ({ b, done: true, date: b.last_date! })), ...due.map((b) => ({ b, done: false, date: b.next_date! }))]; + + const pic = moneyPicture(rows, cats, month, null); const txns = withAccountNames((recent ?? []) as unknown as Txn[]); - type Acct = { type: string; subtype: string | null }; - const bal = (pred: (a: Acct) => boolean) => { - const list = accounts.filter((a) => a.included && pred(a)); - return list.length ? list.reduce((s, a) => s + Number(a.current_balance ?? 0), 0) : null; - }; - const owed = bal((a) => a.type === "credit" || a.type === "loan"); - const tiles = [ - { label: "In your bank", value: bal((a) => a.type === "depository" && a.subtype !== "savings"), href: "/accounts" }, - { label: "Savings", value: bal((a) => a.type === "depository" && a.subtype === "savings"), href: "/accounts" }, - { label: "Investments", value: bal((a) => a.type === "investment"), href: "/accounts" }, - { label: "You owe", value: owed == null ? null : Math.abs(owed), href: "/debt" }, - ].filter((t) => t.value != null); - - const pic = moneyPicture(rows, cats, ymd(monthStart(now)).slice(0, 7), null); const monthName = dateLabel(day, { month: "long" }); + const short = (iso: string) => dateLabel(iso, { month: "short", day: "numeric" }); + const clean = (n: string) => n.replace(/\s*\(\s*\)\s*$/, ""); + const Soon = ({ date }: { date: string }) => (relDay(date, day) ? {relDay(date, day)} : null); return ( -
+
{!profile?.country && } {!!noRate?.length &&

Totals leave out money in {(noRate as string[]).join(", ")}. No exchange rate is available for it.

} -
= 4 ? "@3xl:grid-cols-4" : tiles.length === 3 ? "@3xl:grid-cols-3" : ""}`}> - {tiles.map((t) => ( - - {t.label} - {money0(t.value!)} - - ))} -
+
+ + Activity + Rules + + {synced && Synced {ago(synced)}} + + +
- -
-
-
- Spent in {monthName} - See all +
+ {cashAccts.length ? : ( +
Cash

Add a checking account to see your cash over time.

+ )} +
+
AccountsView all
+
    + {accts.filter((a) => a.included).slice(0, 5).map((a) => ( +
  • + + {accountName(a)}{[a.item?.institution_name, a.mask && `··${a.mask}`, debts.includes(a) && "owed"].filter(Boolean).join(" · ")} + +
  • + ))} +
  • Net worth
  • +
+
+ {[banks.size ? `${banks.size} ${banks.size === 1 ? "bank" : "banks"}` : null, `${accts.length} ${accts.length === 1 ? "account" : "accounts"}`, synced && `synced ${ago(synced)}`].filter(Boolean).join(" · ")} + Add account
-

{money0(pic.spent)}

- {pic.spent > 0 ? ( +
+
+ +

Money movement {monthName}

+
+
+
Money outSee all
+ + {week && ( <> -
- {pic.slices.map((s) =>
)} + + {under ? "↓" : "↑"} {Math.round(Math.abs(1 - week.thisWeek / week.usual) * 100)}% {under ? "under" : "over"} your usual week + +
+ +
-
    - {pic.slices.slice(0, 3).map((s) => ( -
  • +
    Last 7 days {money0(week.thisWeek)}Usual week {money0(week.usual)}
    + + )} + {pic.spent > 0 ? ( +
      + {pic.slices.map((s) => ( +
    • +
      {s.label} - {money0(s.amount)} + +
      +
      +
    • + ))} +
    + ) :

    Nothing yet this month.

    } +
+ +
+
Bills this monthRecurring
+ {monthBills.length ? ( + <> +
+ {paid.length} of {monthBills.length} paid +
+
+
    + {monthBills.slice(0, 7).map(({ b, done, date }) => ( +
  • + + {clean(b.merchant_name)}{done && }{done ? `Paid ${short(date)}` : short(date)} + {!done && } +
  • ))}
- ) :

Nothing yet this month.

} -
- -
-
- Coming up - See all -
- {bills?.length ? ( -
    - {bills.map((b) => ( -
  • - - {(b.merchant_name as string).replace(/\s*\(\s*\)\s*$/, "")} - {dateLabel(b.next_date as string, { month: "short", day: "numeric" })} - {money0(Number(b.average_amount))} -
  • - ))} -
- ) :

Nothing due in the next 2 weeks.

} + ) :

No bills found this month yet.

} + {pay && ( +
+ Money in +
+ + {clean(pay.merchant_name)}{pay.last_date && Last paid {short(pay.last_date)}} + + +
+
+ )}
+ +
- Latest spending - See all + Latest spending + See all
{txns.length ? :

No transactions yet. Press sync in a minute.

}
diff --git a/src/app/(app)/settings/Settings.tsx b/src/app/(app)/settings/Settings.tsx index 509aa8d..289d8e6 100644 --- a/src/app/(app)/settings/Settings.tsx +++ b/src/app/(app)/settings/Settings.tsx @@ -9,7 +9,7 @@ import { modelOptions, saveChoice } from "@/components/Assistant"; import { CountryField } from "@/components/CountryPicker"; import { Dropdown } from "@/components/Dropdown"; import { Modal } from "@/components/Modal"; -import { ThemeToggle } from "@/components/Nav"; +import { SkinPicker, ThemeToggle } from "@/components/Nav"; import { SignOut } from "@/components/SignOut"; import { countryOf } from "@/lib/countries"; import { bandLabel, creditOf, monthText } from "@/lib/credit"; @@ -120,9 +120,14 @@ export function Settings({ signedIn, local, folder, repo, update, email, profile {group === "profile" && } {group === "appearance" && ( - - - + <> + + + + + + + )} {group === "improve" && update && {folder && npm run update}} {group === "improve" && } diff --git a/src/app/globals.css b/src/app/globals.css index 1657913..724bc34 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -23,7 +23,7 @@ --plum: #2b1840; --on-ink: #ffffff; /* text on bg-ink */ --chart-mute: #c7d3fa; - --shadow-card: 0 1px 2px #0000000a, 0 6px 20px -8px #00000014; + --shadow-card: 0 1px 2px #0000000a; /* a hairline lift; the border does the work (Mercury look, 2026-11-10) */ --shadow-pop: 0 1px 3px #0000000f, 0 18px 44px -14px #00000038; --backdrop: #0000004d; /* behind a modal */ color-scheme: light; @@ -90,9 +90,9 @@ body { } button:not(:disabled):active, a:active { transform: scale(.98); } .row-hover:hover, a.row-hover:focus-visible { background: var(--hover); } - .card-link { @apply bg-surface rounded-3xl border border-line; box-shadow: var(--shadow-card); } + .card-link { @apply bg-surface rounded-xl border border-line; box-shadow: var(--shadow-card); } .card-link:hover { background: linear-gradient(0deg, var(--hover), var(--hover)), var(--surface); box-shadow: var(--shadow-pop); } - .card { @apply bg-surface rounded-3xl border border-line; box-shadow: var(--shadow-card); } + .card { @apply bg-surface rounded-xl border border-line; box-shadow: var(--shadow-card); } .card-title { @apply text-[17px] font-semibold tracking-[-0.01em]; } /* Headline money: Current Spend, Safe to Spend, balances. */ .figure { @apply text-[32px] leading-tight font-semibold tracking-[-0.025em] tabular-nums; } @@ -106,4 +106,65 @@ body { .select { @apply w-full bg-surface border border-line rounded-xl px-3 py-2.5 text-sm outline-none focus:border-ink; } .filter { @apply bg-transparent text-sm px-3 py-1.5 rounded-full outline-none hover:bg-[var(--hover)] cursor-pointer; } .tabular { font-variant-numeric: tabular-nums; } + /* Money: cents smaller and lighter so the dollars read first (components/Amount.tsx). */ + .money { font-variant-numeric: tabular-nums; transition: filter var(--dur) var(--ease-out); } + .cents { font-size: .62em; color: var(--muted); margin-left: 1px; vertical-align: .42em; letter-spacing: 0; } + .figure .cents { font-size: .5em; vertical-align: .8em; } + /* Segmented control: 1W / 1M and the like. */ + .seg { @apply inline-flex gap-0.5; } + .seg button { @apply px-2 py-0.5 rounded-md text-xs font-medium text-muted hover:bg-[var(--hover)]; } + .seg button[aria-pressed="true"] { @apply bg-[var(--hover-strong)] text-ink; } } + +/* Hide balances (components/Amount.tsx HideMoney): every .money and headline figure blurs. */ +.hide-money .money, .hide-money .figure { filter: blur(7px); user-select: none; } + +/* Retro theme: Settings > Appearance > Retro. Mac OS X Aqua and iTunes 7, the era of broke's 2006 logo set (design/logo-2000s.png). + Light and dark come from the same System / Light / Dark choice. Charts stay plain in every theme (Max, 2026-11-10). */ +:root[data-skin="retro"] { + --canvas: #e4e7ec; --surface: #ffffff; --ink: #141414; --muted: #545b67; --line: #b3b9c3; + --brand: #2f78dc; --brand-soft: #d9e7fb; --chart: #2f78dc; --chart-soft: #d9e7fb; --chart-mute: #a9c8f2; + --good: #2c862c; --bad: #c3312b; --hover: #0000000d; --hover-strong: #00000017; + --shadow-card: 0 1px 3px #00000024; --shadow-pop: 0 2px 4px #00000026, 0 18px 40px -12px #00000059; + --retro-stripe: #ffffff80; --track-1: #c9ced6; --track-2: #eef0f3; --metal-hi: #eceef1; --metal-lo: #c3c8cf; --gel-top: #ffffff; --gel-mid: #e6e9ee; --gel-low: #d3d8df; --gel-edge: #8f96a1; + --aqua-1: #b6dbff; --aqua-2: #5ea6f6; --aqua-3: #2f7fe6; --aqua-4: #86c2ff; --aqua-edge: #2a5ea8; --sel-1: #70adf4; --sel-2: #2d6fd4; +} +@media (prefers-color-scheme: dark) { + :root[data-skin="retro"]:not([data-theme="light"]) { + --canvas: #1b1c1f; --surface: #25262a; --ink: #ececee; --muted: #a3a6ae; --line: #45474e; + --brand: #64a6ff; --brand-soft: #64a6ff26; --chart: #64a6ff; --chart-soft: #64a6ff26; --chart-mute: #2f4d78; + --good: #5fcf6a; --bad: #ff7b72; --hover: #ffffff0f; --hover-strong: #ffffff1c; + --shadow-card: inset 0 1px 0 #ffffff0d, 0 1px 3px #00000066; --shadow-pop: inset 0 1px 0 #ffffff12, 0 18px 44px -14px #000000b3; + --retro-stripe: #ffffff06; --track-1: #141517; --track-2: #2a2b30; --metal-hi: #3c3d42; --metal-lo: #26272b; --gel-top: #55565d; --gel-mid: #3e3f45; --gel-low: #323338; --gel-edge: #141518; + --aqua-1: #7fb9ff; --aqua-2: #3d86e8; --aqua-3: #1f62c7; --aqua-4: #5b9df5; --aqua-edge: #0f3a7a; --sel-1: #4a8be0; --sel-2: #1f56b0; + } +} +:root[data-skin="retro"][data-theme="dark"] { + --canvas: #1b1c1f; --surface: #25262a; --ink: #ececee; --muted: #a3a6ae; --line: #45474e; + --brand: #64a6ff; --brand-soft: #64a6ff26; --chart: #64a6ff; --chart-soft: #64a6ff26; --chart-mute: #2f4d78; + --good: #5fcf6a; --bad: #ff7b72; --hover: #ffffff0f; --hover-strong: #ffffff1c; + --shadow-card: inset 0 1px 0 #ffffff0d, 0 1px 3px #00000066; --shadow-pop: inset 0 1px 0 #ffffff12, 0 18px 44px -14px #000000b3; + --retro-stripe: #ffffff06; --track-1: #141517; --track-2: #2a2b30; --metal-hi: #3c3d42; --metal-lo: #26272b; --gel-top: #55565d; --gel-mid: #3e3f45; --gel-low: #323338; --gel-edge: #141518; + --aqua-1: #7fb9ff; --aqua-2: #3d86e8; --aqua-3: #1f62c7; --aqua-4: #5b9df5; --aqua-edge: #0f3a7a; --sel-1: #4a8be0; --sel-2: #1f56b0; +} +[data-skin="retro"] body { font-family: "Lucida Grande", "Lucida Sans Unicode", var(--font-figtree), system-ui, sans-serif; + background: repeating-linear-gradient(90deg, #ffffff0d 0 1px, #00000008 1px 3px), linear-gradient(var(--metal-hi), var(--metal-lo)) fixed; } +[data-skin="retro"] main.bg-canvas { background-color: var(--canvas); background-image: repeating-linear-gradient(0deg, var(--retro-stripe) 0 2px, transparent 2px 4px); } +[data-skin="retro"] .card, [data-skin="retro"] .card-link { border-radius: 8px; } +[data-skin="retro"] nav a[aria-current="page"] { background: linear-gradient(var(--sel-1), var(--sel-2)); color: #fff; text-shadow: 0 -1px 0 #00000040; box-shadow: inset 0 1px 0 #ffffff40; } +[data-skin="retro"] .btn, [data-skin="retro"] .pill-tab-active, [data-skin="retro"] .seg button { + border: 1px solid var(--gel-edge); background: linear-gradient(var(--gel-top), var(--gel-mid) 50%, var(--gel-low) 51%, var(--gel-mid)); color: var(--ink); box-shadow: 0 1px 1px #00000022, inset 0 1px 0 #ffffff80; } +[data-skin="retro"] .seg { gap: 0; } +[data-skin="retro"] .seg button { border-radius: 0; margin-left: -1px; padding: 1px 10px; } +[data-skin="retro"] .seg button:first-child { border-radius: 12px 0 0 12px; } +[data-skin="retro"] .seg button:last-child { border-radius: 0 12px 12px 0; } +[data-skin="retro"] .btn-primary, [data-skin="retro"] .seg button[aria-pressed="true"], [data-skin="retro"] .pill-tab-active { + border: 1px solid var(--aqua-edge); color: #fff; text-shadow: 0 -1px 0 #00000040; + background: linear-gradient(var(--aqua-1), var(--aqua-2) 50%, var(--aqua-3) 51%, var(--aqua-4)); box-shadow: 0 1px 2px #00000033, inset 0 1px 0 #ffffff99; } +[data-skin="retro"] .soon, [data-skin="retro"] .chip { background: linear-gradient(var(--aqua-1), var(--aqua-3)); color: #fff; border: 1px solid var(--aqua-edge); text-shadow: 0 -1px 0 #00000033; } +[data-skin="retro"] .chip.text-good { background: linear-gradient(#a6e39a, #3fa33f); border-color: #2b6e2b; } +[data-skin="retro"] .bar { height: 9px; background: linear-gradient(var(--track-1), var(--track-2)); box-shadow: inset 0 1px 2px #00000040; } +[data-skin="retro"] .bar i { background-image: linear-gradient(#ffffff73, #ffffff1a 50%, #00000014 51%) !important; } +[data-skin="retro"] .bar i.bg-good, [data-skin="retro"] .bar i.bg-chart { background-image: repeating-linear-gradient(-45deg, #ffffff40 0 7px, transparent 7px 14px), linear-gradient(#ffffff73, #ffffff1a 50%, #00000014 51%) !important; background-size: 20px 20px, auto; animation: retro-pole 1s linear infinite; } +@keyframes retro-pole { to { background-position: 20px 0, 0 0; } } +@media (prefers-reduced-motion: reduce) { [data-skin="retro"] .bar i { animation: none; } } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b81ea2c..191a463 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -13,8 +13,8 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac return ( - {/* Apply the saved theme before paint; no attribute means follow the system. */} -