"use client"; import Link from "next/link"; import { useEffect } from "react"; import { useQueryClient } from "@tanstack/react-query"; import { Clock, MapPin } from "lucide-react"; import { useRecentParcels } from "@/lib/site-finder-api"; const MAX_SHOWN = 5; export function RecentParcels() { const queryClient = useQueryClient(); const { data: parcels, isLoading } = useRecentParcels(); // The visit is written to localStorage in page.handleParcelOpen, but the // QueryClient survives client-side navigation and useRecentParcels has a 60s // staleTime, so returning to /site-finder otherwise shows a stale snapshot // without the just-opened parcel. Invalidate on mount to refetch the latest // localStorage state (the component re-mounts on each return to the page). useEffect(() => { void queryClient.invalidateQueries({ queryKey: ["recent-parcels"] }); }, [queryClient]); if (isLoading) { return (
{[1, 2, 3].map((i) => (
))}
); } const shown = (parcels ?? []).slice(0, MAX_SHOWN); if (shown.length === 0) { return (
Недавние участки

История просмотров пуста

); } return (
{/* Header */}
Недавние участки
{/* List */}
{shown.map((parcel, idx) => ( { (e.currentTarget as HTMLElement).style.background = "var(--bg-card-alt)"; }} onMouseLeave={(e) => { (e.currentTarget as HTMLElement).style.background = "transparent"; }} >
{parcel.cad_num}
{parcel.district} {parcel.area_ha ? ` · ${parcel.area_ha.toFixed(2)} га` : ""}
))}
); }