Исправлено дублирование блоков документов (ref для отслеживания созданных)

This commit is contained in:
Fedor
2025-11-25 23:36:32 +03:00
parent f058ca91ad
commit 18fcdecae8

View File

@@ -339,21 +339,29 @@ export default function StepWizardPlan({
}, [formValues, questions]);
// Автоматически создаём блоки для ВСЕХ документов из плана при загрузке
// Используем ref чтобы отслеживать какие блоки уже созданы
const createdDocBlocksRef = React.useRef<Set<string>>(new Set());
useEffect(() => {
if (!plan || !documents || documents.length === 0) return;
documents.forEach((doc) => {
const docKey = doc.id || doc.name || `doc_${Math.random()}`;
const docKey = doc.id || doc.name || `doc_unknown`;
// Не создаём блок, если уже создавали
if (createdDocBlocksRef.current.has(docKey)) return;
// Не создаём блок, если документ пропущен
if (skippedDocuments.has(docKey)) return;
const existingBlocks = questionFileBlocks[docKey] || [];
// Помечаем как созданный
createdDocBlocksRef.current.add(docKey);
// Если блока ещё нет, создаём его автоматически
if (existingBlocks.length === 0) {
const category = doc.id && !doc.id.includes('_exist') ? doc.id : docKey;
handleDocumentBlocksChange(docKey, (blocks) => [
const category = doc.id && !doc.id.includes('_exist') ? doc.id : docKey;
handleDocumentBlocksChange(docKey, (blocks) => {
// Проверяем ещё раз внутри callback
if (blocks.length > 0) return blocks;
return [
...blocks,
{
id: generateBlockId(docKey),
@@ -363,10 +371,10 @@ export default function StepWizardPlan({
docLabel: doc.name,
files: [],
},
]);
}
];
});
});
}, [plan, documents, questionFileBlocks, handleDocumentBlocksChange, skippedDocuments]);
}, [plan, documents, handleDocumentBlocksChange, skippedDocuments]);
useEffect(() => {
if (!isWaiting || !formData.session_id || plan) {