mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 19:11:12 -05:00
Refactor: Optimize validation in moderation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useState, useMemo } from 'react';
|
||||
import { AlertCircle, CheckCircle, Info, AlertTriangle } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||
@@ -20,22 +20,21 @@ export function ValidationSummary({ item, onValidationChange, compact = false }:
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
|
||||
// Create stable reference for item_data to prevent unnecessary re-validations
|
||||
const itemDataString = useMemo(
|
||||
() => JSON.stringify(item.item_data),
|
||||
[item.item_data]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
async function validate() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
console.log('Validating submission:', {
|
||||
type: item.item_type,
|
||||
data: item.item_data,
|
||||
id: item.id
|
||||
});
|
||||
|
||||
const result = await validateEntityData(
|
||||
item.item_type as any,
|
||||
{ ...item.item_data, id: item.id }
|
||||
);
|
||||
|
||||
console.log('Validation result:', result);
|
||||
setValidationResult(result);
|
||||
onValidationChange?.(result);
|
||||
} catch (error) {
|
||||
@@ -53,7 +52,7 @@ export function ValidationSummary({ item, onValidationChange, compact = false }:
|
||||
}
|
||||
|
||||
validate();
|
||||
}, [item.item_type, item.item_data, item.id, onValidationChange]);
|
||||
}, [item.item_type, itemDataString, item.id]);
|
||||
|
||||
// Auto-expand when there are blocking errors or warnings
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user