Month Year selection for Dashboard

This commit is contained in:
2026-04-20 23:31:59 -04:00
parent d865b02752
commit 91a33cdfec
5 changed files with 126 additions and 24 deletions

View File

@@ -103,7 +103,7 @@ export function BudgetCard({ budget }: { budget: BudgetWithSpend }) {
{budget.limitCents ? (
<BudgetProgress spendCents={budget.spendCents} limitCents={budget.limitCents} />
) : (
<p className="text-xs text-muted-foreground">This month</p>
<p className="text-xs text-muted-foreground">All time</p>
)}
{!budget.isActive && (

View File

@@ -0,0 +1,52 @@
'use client'
import { useSearchParams, useRouter, usePathname } from 'next/navigation'
import { ChevronLeft, ChevronRight } from 'lucide-react'
import { Button } from '@/components/ui/button'
export function MonthYearPicker() {
const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
const now = new Date()
const currentMonth = now.getMonth() + 1
const currentYear = now.getFullYear()
const month = Number(searchParams.get('month')) || currentMonth
const year = Number(searchParams.get('year')) || currentYear
const isCurrentMonth = month === currentMonth && year === currentYear
function navigate(delta: number) {
let m = month + delta
let y = year
if (m < 1) { m = 12; y-- }
if (m > 12) { m = 1; y++ }
const params = new URLSearchParams(searchParams.toString())
params.set('month', String(m))
params.set('year', String(y))
router.push(`${pathname}?${params.toString()}`)
}
const label = new Date(year, month - 1, 1).toLocaleDateString('en-US', {
month: 'long', year: 'numeric',
})
return (
<div className="flex items-center gap-1">
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => navigate(-1)}>
<ChevronLeft className="h-4 w-4" />
</Button>
<span className="text-sm font-medium min-w-[140px] text-center">{label}</span>
<Button
variant="ghost"
size="icon"
className="h-7 w-7"
onClick={() => navigate(1)}
disabled={isCurrentMonth}
>
<ChevronRight className="h-4 w-4" />
</Button>
</div>
)
}

View File

@@ -4,7 +4,7 @@ import { formatCents } from '@/lib/utils/currency'
interface BankAccount {
id: string
name: string
currentBalanceCents: number
balanceCents: number
}
interface NetWorthCardProps {
@@ -26,7 +26,7 @@ export function NetWorthCard({ netWorthCents, bankAccounts }: NetWorthCardProps)
<div key={a.id} className="flex items-center justify-between text-sm">
<span className="text-muted-foreground truncate">{a.name}</span>
<span className="tabular-nums font-medium ml-4 shrink-0">
{formatCents(a.currentBalanceCents)}
{formatCents(a.balanceCents)}
</span>
</div>
))}