From 3e11eef1c4c92932e3f985de19a59d04ca838795 Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Sat, 21 Mar 2026 17:07:01 -0600 Subject: [PATCH] feat(13-03): add aiPlacementKey prop to FieldPlacer and thread through PdfViewerWrapper/PdfViewer - Add aiPlacementKey?: number to FieldPlacerProps interface - Add aiPlacementKey to loadFields useEffect dependency array for re-fetch on AI placement - Thread aiPlacementKey through PdfViewer and PdfViewerWrapper prop chains --- .../documents/[docId]/_components/FieldPlacer.tsx | 8 +++++--- .../documents/[docId]/_components/PdfViewer.tsx | 3 +++ .../documents/[docId]/_components/PdfViewerWrapper.tsx | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx index 43340dd..aeb766d 100644 --- a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx +++ b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx @@ -163,9 +163,10 @@ interface FieldPlacerProps { textFillData?: Record; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; } -export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false, onFieldsChanged, selectedFieldId, textFillData, onFieldSelect, onFieldValueChange }: FieldPlacerProps) { +export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false, onFieldsChanged, selectedFieldId, textFillData, onFieldSelect, onFieldValueChange, aiPlacementKey = 0 }: FieldPlacerProps) { const [fields, setFields] = useState([]); const [isDraggingToken, setIsDraggingToken] = useState(null); const containerRef = useRef(null); @@ -198,7 +199,8 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = useSensor(TouchSensor, { activationConstraint: { delay: 150, tolerance: 5 } }), ); - // Load existing fields from server on mount + // Load existing fields from server on mount and whenever aiPlacementKey changes + // aiPlacementKey increments after AI placement so this re-fetches AI-placed fields from DB useEffect(() => { async function loadFields() { try { @@ -212,7 +214,7 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = } } loadFields(); - }, [docId]); + }, [docId, aiPlacementKey]); // Update containerSize whenever pageInfo changes (page load or zoom change) // Use pageInfo.width/height (from react-pdf canvas) as the authoritative rendered size. diff --git a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx index b1dce2d..c3dceb9 100644 --- a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx +++ b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx @@ -27,6 +27,7 @@ export function PdfViewer({ textFillData, onFieldSelect, onFieldValueChange, + aiPlacementKey, }: { docId: string; docStatus?: string; @@ -35,6 +36,7 @@ export function PdfViewer({ textFillData?: Record; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; }) { const [numPages, setNumPages] = useState(0); const [pageNumber, setPageNumber] = useState(1); @@ -95,6 +97,7 @@ export function PdfViewer({ textFillData={textFillData} onFieldSelect={onFieldSelect} onFieldValueChange={onFieldValueChange} + aiPlacementKey={aiPlacementKey} > ; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; }) { return ( ); }