Refactor the rqbit-web file by breaking it down into components and helper functions. Improve code organization and maintainability

This commit is contained in:
Artur Lozovski 2023-12-07 16:33:37 +00:00
parent a5e7a5a5f5
commit f978ad02fe
25 changed files with 1722 additions and 926 deletions

View file

@ -0,0 +1,49 @@
import { RefObject, useRef, useState } from "react";
import { UploadButton } from "./UploadButton";
export const FileInput = () => {
const inputRef = useRef<HTMLInputElement>() as RefObject<HTMLInputElement>;
const [file, setFile] = useState<File | null>(null);
const onFileChange = async () => {
if (!inputRef?.current?.files) {
return;
}
const file = inputRef.current.files[0];
setFile(file);
};
const reset = () => {
if (!inputRef?.current) {
return;
}
inputRef.current.value = "";
setFile(null);
};
const onClick = () => {
if (!inputRef?.current) {
return;
}
inputRef.current.click();
};
return (
<>
<input
type="file"
ref={inputRef}
accept=".torrent"
onChange={onFileChange}
className="d-none"
/>
<UploadButton
variant="secondary"
buttonText="Upload .torrent File"
onClick={onClick}
data={file}
resetData={reset}
/>
</>
);
};