import { Link } from 'react-router-dom' import { authClient } from '../lib/auth-client.ts' import { usePurchases, usePriceAlerts } from '../hooks/useApi.ts' import { StoreIcon } from '../components/StoreIcon.tsx' export function Dashboard() { const { data: session, isPending } = authClient.useSession() if (isPending) { return } if (!session) { return (

CartSnitch

Track prices. Save money.

Sign In Create Account
) } return } function AuthenticatedDashboard({ userName }: { userName: string }) { const { data: purchases = [], isLoading: purchasesLoading } = usePurchases() const { data: alerts = [], isLoading: alertsLoading } = usePriceAlerts() const triggeredAlerts = alerts.filter((a) => a.triggered) const watchingAlerts = alerts.filter((a) => !a.triggered) const recentPurchases = purchases.slice(0, 3) if (purchasesLoading || alertsLoading) { return } return (

Hi, {userName.split(' ')[0]}

{/* Triggered alerts banner */} {triggeredAlerts.length > 0 && (

{triggeredAlerts.length} price {triggeredAlerts.length === 1 ? 'alert' : 'alerts'} triggered!

{triggeredAlerts.map((a) => a.productName).join(', ')}

)} {/* Quick stats */}

Watching

{watchingAlerts.length}

price alerts

This Month

${recentPurchases.reduce((sum, p) => sum + p.total, 0).toFixed(0)}

grocery spend

{/* Price trend sparklines */}

Price Trends

Connect a store to see price trends
{/* Recent purchases */}

Recent Purchases

View all
{recentPurchases.map((purchase) => (

{purchase.storeName}

{new Date(purchase.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', })}{' '} · {purchase.items.length} items

${purchase.total.toFixed(2)} ))}
{/* Quick actions */}

Quick Actions

Compare Prices Link a Store
) } function DashboardSkeleton() { return (

Loading CartSnitch…

) }