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