Created useFormatters() combining useWeightUnit + useCurrency + formatWeight/formatPrice into a single hook returning weight(grams) and price(cents) bound functions plus raw unit and currency values. Updated all 14 consumer files to use the new hook, removing the repeated 4-import + 2-hook-call pattern from each. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { createFileRoute } from "@tanstack/react-router";
|
|
import { DashboardCard } from "../components/DashboardCard";
|
|
import { useFormatters } from "../hooks/useFormatters";
|
|
import { useSetups } from "../hooks/useSetups";
|
|
import { useThreads } from "../hooks/useThreads";
|
|
import { useTotals } from "../hooks/useTotals";
|
|
|
|
export const Route = createFileRoute("/")({
|
|
component: DashboardPage,
|
|
});
|
|
|
|
function DashboardPage() {
|
|
const { data: totals } = useTotals();
|
|
const { data: threads } = useThreads(false);
|
|
const { data: setups } = useSetups();
|
|
const { weight, price } = useFormatters();
|
|
|
|
const global = totals?.global;
|
|
const activeThreadCount = threads?.length ?? 0;
|
|
const setupCount = setups?.length ?? 0;
|
|
|
|
return (
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
|
<DashboardCard
|
|
to="/collection"
|
|
title="Collection"
|
|
icon="backpack"
|
|
stats={[
|
|
{ label: "Items", value: String(global?.itemCount ?? 0) },
|
|
{
|
|
label: "Weight",
|
|
value: weight(global?.totalWeight ?? null),
|
|
},
|
|
{
|
|
label: "Cost",
|
|
value: price(global?.totalCost ?? null),
|
|
},
|
|
]}
|
|
emptyText="Get started"
|
|
/>
|
|
<DashboardCard
|
|
to="/collection"
|
|
search={{ tab: "planning" }}
|
|
title="Planning"
|
|
icon="search"
|
|
stats={[
|
|
{ label: "Active threads", value: String(activeThreadCount) },
|
|
]}
|
|
/>
|
|
<DashboardCard
|
|
to="/collection"
|
|
search={{ tab: "setups" }}
|
|
title="Setups"
|
|
icon="tent"
|
|
stats={[{ label: "Setups", value: String(setupCount) }]}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|