Skip to content
Snippets Groups Projects
Commit 2836fa40 authored by a2-imeri's avatar a2-imeri
Browse files

Add Upluad Button

parent 06459f44
Branches
No related tags found
No related merge requests found
Pipeline #8316 canceled
// src/components/Common/input/FileInput.js
import React, { useRef } from 'react'; import React, { useRef } from 'react';
import { FaUpload, FaTrash } from 'react-icons/fa'; import { FaUpload, FaTrash } from 'react-icons/fa';
import '../../../styles/input/FileInput.css'; import '../../../styles/input/FileInput.css';
......
// src/components/Common/input/NumberInput.js
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import '../../../styles/input/NumberInput.css'; import '../../../styles/input/NumberInput.css';
......
// Src/Component/Detection/Video/VideoInputs.js
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import Dropdown from '../../Common/input/Dropdown'; import Dropdown from '../../Common/input/Dropdown';
import NumberInput from '../../Common/input/NumberInput'; import NumberInput from '../../Common/input/NumberInput';
......
// src/components/detection/video/VideoUploadForm.js
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Form, Button } from 'react-bootstrap'; import { Form, Button } from 'react-bootstrap';
import VideoInputs from './VideoInputs'; import VideoInputs from './VideoInputs';
import { getVideoDuration, calculateMinimumValidFrameDelay, calculateMaximumDelay, calculateExpectedLength, calculateOptimalValues, calculateValidFramesJumpOptions, isDelayPerFrameValid } from './videoUtils'; import FileInput from '../../Common/input/FileInput';
import {
getVideoDuration,
calculateMinimumValidFrameDelay,
calculateMaximumDelay,
calculateExpectedLength,
calculateOptimalValues,
calculateValidFramesJumpOptions,
isDelayPerFrameValid
} from './videoUtils';
const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChange, handleFrameDelayChange, framesJump, frameDelay, isLoading }) => { const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChange, handleFrameDelayChange, framesJump, frameDelay, isLoading }) => {
const [videoFile, setVideoFile] = useState(null); const [videoFile, setVideoFile] = useState(null);
...@@ -11,6 +22,7 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang ...@@ -11,6 +22,7 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang
const [minFrameDelay, setMinFrameDelay] = useState(1); const [minFrameDelay, setMinFrameDelay] = useState(1);
const [isVideoUploaded, setIsVideoUploaded] = useState(false); const [isVideoUploaded, setIsVideoUploaded] = useState(false);
const [validFramesJumpOptions, setValidFramesJumpOptions] = useState([]); const [validFramesJumpOptions, setValidFramesJumpOptions] = useState([]);
const [fileName, setFileName] = useState('');
useEffect(() => { useEffect(() => {
if (videoFile) { if (videoFile) {
...@@ -24,6 +36,7 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang ...@@ -24,6 +36,7 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang
handleFrameDelayChange({ target: { value: frameDelay } }); handleFrameDelayChange({ target: { value: frameDelay } });
setValidFramesJumpOptions(calculateValidFramesJumpOptions(duration)); setValidFramesJumpOptions(calculateValidFramesJumpOptions(duration));
setIsVideoUploaded(true); setIsVideoUploaded(true);
setFileName(videoFile.name);
}).catch(error => { }).catch(error => {
console.error('Error getting video duration:', error); console.error('Error getting video duration:', error);
}); });
...@@ -54,11 +67,22 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang ...@@ -54,11 +67,22 @@ const VideoUploadForm = ({ handleFileChange, handleSubmit, handleFramesJumpChang
handleFileChange(event); handleFileChange(event);
}; };
const handleRemoveFile = () => {
setVideoFile(null);
setIsVideoUploaded(false);
setFileName('');
};
return ( return (
<Form onSubmit={handleSubmit}> <Form onSubmit={handleSubmit}>
<Form.Group controlId="videoFile"> <Form.Group controlId="videoFile">
<Form.Label>Upload Video</Form.Label> <FileInput
<Form.Control type="file" accept="video/*" onChange={handleFileInputChange} disabled={isLoading} /> label="Upload Video"
onChange={handleFileInputChange}
fileName={fileName}
disabled={isLoading}
onRemove={handleRemoveFile}
/>
</Form.Group> </Form.Group>
{isVideoUploaded && ( {isVideoUploaded && (
<VideoInputs <VideoInputs
......
// Src/Component/Detection/Video/VideoInputs.js
export const getVideoDuration = (file) => { export const getVideoDuration = (file) => {
return new Promise((resolve) => { return new Promise((resolve) => {
const video = document.createElement('video'); const video = document.createElement('video');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment