({ content, onUseImageAsInput, onImageClick, originalImageUrl })
| 15 | type ImageSelection = 'Original' | 'Line Art' | 'Final Result'; |
| 16 | |
| 17 | const ResultDisplay: React.FC<ResultDisplayProps> = ({ content, onUseImageAsInput, onImageClick, originalImageUrl }) => { |
| 18 | const { t } = useTranslation(); |
| 19 | const [viewMode, setViewMode] = useState<ViewMode>('result'); |
| 20 | const [twoStepViewMode, setTwoStepViewMode] = useState<TwoStepViewMode>('result'); |
| 21 | |
| 22 | const sliderContainerRef = useRef<HTMLDivElement>(null); |
| 23 | const [sliderPosition, setSliderPosition] = useState(50); |
| 24 | const [isDragging, setIsDragging] = useState(false); |
| 25 | |
| 26 | const [sliderLeft, setSliderLeft] = useState<ImageSelection>('Original'); |
| 27 | const [sliderRight, setSliderRight] = useState<ImageSelection>('Final Result'); |
| 28 | |
| 29 | useEffect(() => { |
| 30 | const handleMouseMove = (e: MouseEvent) => { |
| 31 | if (!isDragging || !sliderContainerRef.current) return; |
| 32 | const rect = sliderContainerRef.current.getBoundingClientRect(); |
| 33 | const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); |
| 34 | const percent = (x / rect.width) * 100; |
| 35 | setSliderPosition(percent); |
| 36 | }; |
| 37 | |
| 38 | const handleMouseUp = () => setIsDragging(false); |
| 39 | |
| 40 | if (isDragging) { |
| 41 | window.addEventListener('mousemove', handleMouseMove); |
| 42 | window.addEventListener('mouseup', handleMouseUp); |
| 43 | } |
| 44 | |
| 45 | return () => { |
| 46 | window.removeEventListener('mousemove', handleMouseMove); |
| 47 | window.removeEventListener('mouseup', handleMouseUp); |
| 48 | }; |
| 49 | }, [isDragging]); |
| 50 | |
| 51 | const handleMouseDown = () => setIsDragging(true); |
| 52 | |
| 53 | const handleDownload = () => { |
| 54 | if (!content.imageUrl) return; |
| 55 | const fileExtension = content.imageUrl.split(';')[0].split('/')[1] || 'png'; |
| 56 | downloadImage(content.imageUrl, `generated-image-${Date.now()}.${fileExtension}`); |
| 57 | }; |
| 58 | |
| 59 | const handleDownloadBoth = () => { |
| 60 | if (content.secondaryImageUrl) { |
| 61 | downloadImage(content.secondaryImageUrl, `line-art-${Date.now()}.png`); |
| 62 | } |
| 63 | if (content.imageUrl) { |
| 64 | downloadImage(content.imageUrl, `final-result-${Date.now()}.png`); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | const handleDownloadComparison = useCallback(async () => { |
| 69 | const imagesToLoad: {url: string | null, img: HTMLImageElement}[] = [ |
| 70 | { url: originalImageUrl, img: new Image() }, |
| 71 | ]; |
| 72 | if (content.secondaryImageUrl && content.imageUrl) { |
| 73 | imagesToLoad.push({ url: content.secondaryImageUrl, img: new Image() }); |
| 74 | imagesToLoad.push({ url: content.imageUrl, img: new Image() }); |
nothing calls this directly
no test coverage detected