({
onRequestClose,
...props
}: FeedbackModalProps)
| 46 | ]; |
| 47 | |
| 48 | const FeedbackModal = ({ |
| 49 | onRequestClose, |
| 50 | ...props |
| 51 | }: FeedbackModalProps): ReactElement => { |
| 52 | const { displayToast } = useToastNotification(); |
| 53 | const { themeMode } = useSettingsContext(); |
| 54 | const fileInputRef = useRef<HTMLInputElement>(null); |
| 55 | const hasSubmitted = useRef(false); |
| 56 | |
| 57 | const [category, setCategory] = useState<FeedbackCategory>( |
| 58 | FeedbackCategory.BugReport, |
| 59 | ); |
| 60 | const [description, setDescription] = useState(''); |
| 61 | const [screenshot, setScreenshot] = useState<File | null>(null); |
| 62 | const [screenshotPreview, setScreenshotPreview] = useState<string | null>( |
| 63 | null, |
| 64 | ); |
| 65 | const [isCapturing, setIsCapturing] = useState(false); |
| 66 | const [isCropping, setIsCropping] = useState(false); |
| 67 | |
| 68 | // Clean up preview URL when component unmounts or screenshot changes |
| 69 | useEffect(() => { |
| 70 | return () => { |
| 71 | if (screenshotPreview) { |
| 72 | revokePreviewUrl(screenshotPreview); |
| 73 | } |
| 74 | }; |
| 75 | }, [screenshotPreview]); |
| 76 | |
| 77 | // Validate the incoming file BEFORE revoking the current preview URL, so |
| 78 | // a rejected replacement (or an oversized crop result) leaves the existing |
| 79 | // attachment and its preview intact. |
| 80 | const handleScreenshotChange = useCallback( |
| 81 | (file: File | null) => { |
| 82 | if (file && !isValidImageType(file)) { |
| 83 | displayToast('Invalid image type. Use PNG, JPG, WebP, or GIF.'); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if (file && !isValidFileSize(file)) { |
| 88 | displayToast( |
| 89 | `File too large. Maximum size is ${ |
| 90 | MAX_SCREENSHOT_SIZE / 1024 / 1024 |
| 91 | }MB.`, |
| 92 | ); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | if (screenshotPreview) { |
| 97 | revokePreviewUrl(screenshotPreview); |
| 98 | } |
| 99 | |
| 100 | setIsCropping(false); |
| 101 | setScreenshot(file); |
| 102 | setScreenshotPreview(file ? createPreviewUrl(file) : null); |
| 103 | }, |
| 104 | [screenshotPreview, displayToast], |
| 105 | ); |
nothing calls this directly
no test coverage detected