refactor(web): type the search history list, fetch only what we render
Replace the `any[]` history query with a small VehicleHistoryItem interface covering the fields the row renders, and lower the API limit from 20 to 6 since the UI slices to 6 anyway (saved bandwidth + correct types on .map). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,15 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
const VIN_REGEX = /^[A-HJ-NPR-Z0-9]{17}$/;
|
||||
|
||||
interface VehicleHistoryItem {
|
||||
id: string;
|
||||
vin: string;
|
||||
brandName: string;
|
||||
model: string | null;
|
||||
year: number | null;
|
||||
lastAccessedAt: string | null;
|
||||
}
|
||||
|
||||
function isValidVin(vin: string): boolean {
|
||||
if (!vin || vin.length !== 17) return false;
|
||||
return VIN_REGEX.test(vin.toUpperCase());
|
||||
@@ -139,7 +148,7 @@ function SearchPage() {
|
||||
|
||||
const { data: history } = useQuery({
|
||||
queryKey: ["vehicles", "history"],
|
||||
queryFn: () => api.get<any[]>("/vehicles/history?limit=20"),
|
||||
queryFn: () => api.get<VehicleHistoryItem[]>("/vehicles/history?limit=6"),
|
||||
});
|
||||
|
||||
// ─── Ctrl+K shortcut ───────────────────────────────────────────────────────
|
||||
@@ -696,7 +705,7 @@ function SearchPage() {
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
{history.slice(0, 6).map((v: any, idx: number) => (
|
||||
{history.map((v, idx) => (
|
||||
<button
|
||||
key={v.id}
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user