feat(01-03): add data hooks, utilities, UI store, and foundational components
- API fetch wrapper with error handling and multipart upload - Weight/price formatters for display - TanStack Query hooks for items, categories, and totals with cache invalidation - Zustand UI store for panel and confirm dialog state - TotalsBar, CategoryHeader, ItemCard, ConfirmDialog, ImageUpload components Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
31
src/client/hooks/useTotals.ts
Normal file
31
src/client/hooks/useTotals.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiGet } from "../lib/api";
|
||||
|
||||
interface CategoryTotals {
|
||||
categoryId: number;
|
||||
categoryName: string;
|
||||
categoryEmoji: string;
|
||||
totalWeight: number;
|
||||
totalCost: number;
|
||||
itemCount: number;
|
||||
}
|
||||
|
||||
interface GlobalTotals {
|
||||
totalWeight: number;
|
||||
totalCost: number;
|
||||
itemCount: number;
|
||||
}
|
||||
|
||||
interface TotalsResponse {
|
||||
categories: CategoryTotals[];
|
||||
global: GlobalTotals;
|
||||
}
|
||||
|
||||
export type { CategoryTotals, GlobalTotals, TotalsResponse };
|
||||
|
||||
export function useTotals() {
|
||||
return useQuery({
|
||||
queryKey: ["totals"],
|
||||
queryFn: () => apiGet<TotalsResponse>("/api/totals"),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user