diff --git a/apps/frontend/src/components/launches/helpers/media.settings.component.tsx b/apps/frontend/src/components/launches/helpers/media.settings.component.tsx index b06ee1eb..581d2088 100644 --- a/apps/frontend/src/components/launches/helpers/media.settings.component.tsx +++ b/apps/frontend/src/components/launches/helpers/media.settings.component.tsx @@ -84,7 +84,7 @@ export const useMediaSettings = () => { }; export const CreateThumbnail: FC<{ - onSelect: (blob: Blob) => void; + onSelect: (blob: Blob, timestampMs: number) => void; media: | { id: string; @@ -100,12 +100,10 @@ export const CreateThumbnail: FC<{ const { onSelect, media, altText, onAltTextChange } = props; const videoRef = useRef(null); const canvasRef = useRef(null); - const fileInputRef = useRef(null); const [currentTime, setCurrentTime] = useState(0); const [duration, setDuration] = useState(0); const [isLoaded, setIsLoaded] = useState(false); const [isCapturing, setIsCapturing] = useState(false); - const [mode, setMode] = useState<'frame' | 'upload'>('frame'); const handleLoadedMetadata = useCallback(() => { if (videoRef.current) { @@ -150,11 +148,14 @@ export const CreateThumbnail: FC<{ // Draw current frame to canvas ctx.drawImage(video, 0, 0, canvas.width, canvas.height); + // Get timestamp in milliseconds + const timestampMs = Math.round(currentTime * 1000); + // Convert canvas to blob canvas.toBlob( (blob: Blob | null) => { if (blob) { - onSelect(blob); + onSelect(blob, timestampMs); } setIsCapturing(false); }, @@ -178,10 +179,13 @@ export const CreateThumbnail: FC<{ tempCanvas.height = video.videoHeight; tempCtx.drawImage(video, 0, 0); + // Get timestamp in milliseconds + const timestampMs = Math.round(currentTime * 1000); + tempCanvas.toBlob( (blob: Blob | null) => { if (blob) { - onSelect(blob); + onSelect(blob, timestampMs); } setIsCapturing(false); }, @@ -198,7 +202,7 @@ export const CreateThumbnail: FC<{ setIsCapturing(false); } } - }, [onSelect]); + }, [onSelect, currentTime]); const formatTime = useCallback((seconds: number) => { const mins = Math.floor(seconds / 60); @@ -206,156 +210,57 @@ export const CreateThumbnail: FC<{ return `${mins}:${secs.toString().padStart(2, '0')}`; }, []); - const handleFileUpload = useCallback( - (event: React.ChangeEvent) => { - const file = event.target.files?.[0]; - if (file && file.type.startsWith('image/')) { - onSelect(file); - } - }, - [onSelect] - ); - - const triggerFileUpload = useCallback(() => { - fileInputRef.current?.click(); - }, []); - if (!media) return null; return (
- {/* Mode Toggle */} -
- - +
+
- {/* Hidden file input */} - - - {mode === 'frame' ? ( + {isLoaded && ( <> -
-
- - {isLoaded && ( - <> -
- -
- {formatTime(currentTime)} - {formatTime(duration)} -
-
- -
- -
- - )} - - ) : ( -
-
- - - -
-

Upload a custom thumbnail image

-

- PNG, JPG, JPEG up to 10MB -

+
+ {formatTime(currentTime)} + {formatTime(duration)}
- -
+ {isCapturing ? 'Capturing...' : 'Select This Frame'} + +
+ )}