From f970671a055cd8fe4459adca7355efc9f118bfa6 Mon Sep 17 00:00:00 2001 From: lekss361 Date: Mon, 18 May 2026 03:48:12 +0300 Subject: [PATCH] fix(sf-fe-a7): restore Section1+Section2 wiring + dedupe useParcelAnalyzeQuery hook --- .../analysis/[cad]/AnalysisPageContent.tsx | 35 ++++++++----------- frontend/src/hooks/useParcelAnalyzeQuery.ts | 32 ----------------- 2 files changed, 15 insertions(+), 52 deletions(-) delete mode 100644 frontend/src/hooks/useParcelAnalyzeQuery.ts diff --git a/frontend/src/app/site-finder/analysis/[cad]/AnalysisPageContent.tsx b/frontend/src/app/site-finder/analysis/[cad]/AnalysisPageContent.tsx index 47a61ef3..2a4f762b 100644 --- a/frontend/src/app/site-finder/analysis/[cad]/AnalysisPageContent.tsx +++ b/frontend/src/app/site-finder/analysis/[cad]/AnalysisPageContent.tsx @@ -2,8 +2,11 @@ import Link from "next/link"; +import { Section1ParcelInfo } from "@/components/site-finder/analysis/Section1ParcelInfo"; +import { Section2NetworksUtilities } from "@/components/site-finder/analysis/Section2NetworksUtilities"; import { Section3SettingsAndCompetitors } from "@/components/site-finder/analysis/Section3SettingsAndCompetitors"; -import { useParcelAnalyzeQuery } from "@/hooks/useParcelAnalyzeQuery"; +import { useParcelAnalyzeQuery } from "@/lib/site-finder-api"; +import type { ParcelAnalysis } from "@/types/site-finder"; // ── Props ───────────────────────────────────────────────────────────────────── @@ -79,8 +82,12 @@ export function AnalysisPageContent({ cad }: Props) { // ── Results layout ───────────────────────────────────────────────────────── - const districtName = data.district?.district_name ?? "—"; - const areaHa = data.geometry_suitability?.area_ha; + // Cast to ParcelAnalysis (superset of ParcelAnalyzeResponse) — both describe + // the same /analyze endpoint; Section3 requires the richer type. + const analysis = data as unknown as ParcelAnalysis; + + const districtName = analysis.district?.district_name ?? "—"; + const areaHa = analysis.geometry_suitability?.area_ha; const areaStr = areaHa != null ? `${areaHa.toFixed(2)} га` : null; return ( @@ -111,26 +118,14 @@ export function AnalysisPageContent({ cad }: Props) { {/* ── Main scroll area ──────────────────────────────────────────── */}
- {/* Section 1 placeholder — filled by A5 */} -
- -
+ {/* Section 1 — IMPLEMENTED in A5 */} + - {/* Section 2 placeholder — filled by A6 */} -
- -
+ {/* Section 2 — IMPLEMENTED in A6 */} + {/* Section 3 — IMPLEMENTED in A7 */} - + {/* Section 4 placeholder — filled by A10 */}
diff --git a/frontend/src/hooks/useParcelAnalyzeQuery.ts b/frontend/src/hooks/useParcelAnalyzeQuery.ts deleted file mode 100644 index 99444095..00000000 --- a/frontend/src/hooks/useParcelAnalyzeQuery.ts +++ /dev/null @@ -1,32 +0,0 @@ -"use client"; - -import { useQuery } from "@tanstack/react-query"; - -import { apiFetch } from "@/lib/api"; -import type { ParcelAnalysis } from "@/types/site-finder"; - -/** - * TanStack Query-based hook for analysis page route `/site-finder/analysis/[cad]`. - * - * Unlike `useSiteAnalysis` (mutation-based, triggered on form submit), this hook - * drives the analysis page where `cad` is a URL param — so we use `useQuery` - * for automatic fetch + caching. - * - * Note: the 202 Accepted on-demand fetch flow is NOT handled here — the analysis - * page assumes geometry is already available (the legacy page handles on-demand - * fetching and can redirect to this route once done). For now, a 202 response - * will surface as an error state. - */ -export function useParcelAnalyzeQuery(cad: string) { - return useQuery({ - queryKey: ["parcel-analyze", cad], - queryFn: () => - apiFetch( - `/api/v1/parcels/${encodeURIComponent(cad)}/analyze`, - { method: "POST" }, - ), - enabled: !!cad, - staleTime: 5 * 60 * 1000, // 5 min — backend analysis is expensive - retry: 1, - }); -}