From 82948ada923dd421afa9caf7a68d167ee5314332 Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Wed, 22 Apr 2026 11:20:43 +0300 Subject: [PATCH] fix: improve debug panel layout and log display - Clear logs between rotation updates (no more expanding text) - Increase canvas size from 600x450 to 900x600 for better visibility - Reorganize layout: left controls, right canvas + single-line log - Make crop box much larger and easier to see --- frontend/components/DebugRotationPanel.tsx | 99 +++++++++------------- 1 file changed, 42 insertions(+), 57 deletions(-) diff --git a/frontend/components/DebugRotationPanel.tsx b/frontend/components/DebugRotationPanel.tsx index 0875251d..531d56ea 100644 --- a/frontend/components/DebugRotationPanel.tsx +++ b/frontend/components/DebugRotationPanel.tsx @@ -25,10 +25,11 @@ export function DebugRotationPanel({ }: DebugRotationPanelProps) { const [rotation, setRotation] = useState(originalRotation); const canvasRef = useRef(null); - const [logs, setLogs] = useState([]); + const [log, setLog] = useState(''); const imageRef = useRef(null); const [imageLoaded, setImageLoaded] = useState(false); const [scaledDimensions, setScaledDimensions] = useState({ width: 0, height: 0, scale: 1 }); + const containerRef = useRef(null); // Use original photo path if available, otherwise fall back to processed image URL const displayImageUrl = originalPhotoPath ? originalPhotoPath : imageUrl; @@ -44,8 +45,8 @@ export function DebugRotationPanel({ { label: '±180°', value: 180 }, ]; - const addLog = (message: string) => { - setLogs((prev) => [...prev, `[${new Date().toLocaleTimeString()}] ${message}`]); + const updateLog = (message: string) => { + setLog(message); }; useEffect(() => { @@ -54,18 +55,17 @@ export function DebugRotationPanel({ img.onload = () => { imageRef.current = img; setImageLoaded(true); - addLog(`šŸ“ø Image loaded: ${img.width}Ɨ${img.height}px`); - // Calculate scaled dimensions to fit canvas - const maxWidth = 600; - const maxHeight = 500; + // Calculate scaled dimensions to fit available space (much larger) + const maxWidth = 900; + const maxHeight = 600; const scale = Math.min(maxWidth / img.width, maxHeight / img.height); const scaledW = img.width * scale; const scaledH = img.height * scale; setScaledDimensions({ width: scaledW, height: scaledH, scale }); - addLog(`šŸ“ Scaled to fit: ${scaledW.toFixed(0)}Ɨ${scaledH.toFixed(0)}px (scale ${scale.toFixed(2)}x)`); + updateLog(`šŸ“ø ${img.width}Ɨ${img.height}px → scaled ${scaledW.toFixed(0)}Ɨ${scaledH.toFixed(0)}px (${scale.toFixed(2)}x)`); }; - img.onerror = () => addLog('āŒ Failed to load image'); + img.onerror = () => updateLog('āŒ Failed to load image'); img.src = displayImageUrl; }, [displayImageUrl]); @@ -83,13 +83,10 @@ export function DebugRotationPanel({ canvas.width = scaledDimensions.width; canvas.height = scaledDimensions.height; - addLog(`\nšŸŽØ --- Drawing Preview ---`); - addLog(`Rotation: ${rotation}°`); - // Draw scaled image ctx.drawImage(img, 0, 0, canvas.width, canvas.height); - // Draw crop bounding box on the ORIGINAL image + // Calculate crop box in scaled coordinates const cropX = originalCropBounds.x * scale; const cropY = originalCropBounds.y * scale; const cropW = originalCropBounds.width * scale; @@ -126,35 +123,32 @@ export function DebugRotationPanel({ ctx.restore(); - // Logs - addLog(`Crop area: (${originalCropBounds.x}, ${originalCropBounds.y}) ${originalCropBounds.width}Ɨ${originalCropBounds.height}px`); - addLog(`Scaled crop: (${cropX.toFixed(0)}, ${cropY.toFixed(0)}) ${cropW.toFixed(0)}Ɨ${cropH.toFixed(0)}px`); - if (Math.abs(rotation) > 0.5) { - addLog(`āœ… Rotation overlay shown in ORANGE`); - } + // Update log with current state + const logText = `Rotation: ${rotation}° | Crop: (${cropX.toFixed(0)}, ${cropY.toFixed(0)}) ${cropW.toFixed(0)}Ɨ${cropH.toFixed(0)}px`; + updateLog(logText); }, [imageLoaded, rotation, originalCropBounds, scaledDimensions]); return ( -
-
+
+
{/* Header */} -
-

šŸ”§ Debug Rotation & Crop

+
+

Debug Rotation & Crop

-
+
{/* Left: Controls */} -
+
{/* Rotation Slider */}
-