ahaha / src /UploadForm.jsx
zerinf
biorxiv release
5aec4d0
Raw History Blame Contribute Delete
5.88 kB
import { useState, useRef } from 'react';
import { Tooltip } from 'react-tooltip';
import 'bootstrap/dist/css/bootstrap.min.css';
import './UploadForm.css';
function UploadForm({
selectedFile, setSelectedFile,
formData, setFormData,
statusText,
handleSubmit
}) {
const [isLoadingDemoData, setIsLoadingDemoData] = useState(false);
const fileInputRef = useRef(null);
const isDisabled = isLoadingDemoData || statusText != 'Start Analysis';
const handleFileChange = (e) => {
setSelectedFile(e.target.files[0]);
}
const handleInputChange = (e) => {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
};
const handleLoadDemoData = async (e) => {
e.preventDefault();
setIsLoadingDemoData(true);
setFormData({
tilt: 20.0,
num_threshold: 10,
entropy_threshold: 0.01,
n_plots: 10
});
try {
const response = await fetch('/demo.cs');
if (!response.ok) {
alert('Failed to load demo data.');
}
const demoFileBlob = await response.blob();
const demoFile = new File([demoFileBlob], 'demo.cs', {type: 'application/octet-stream'});
if (fileInputRef.current) {
const dataTransfer = new DataTransfer();
dataTransfer.items.add(demoFile);
fileInputRef.current.files = dataTransfer.files;
fileInputRef.current.dispatchEvent(new Event('change', { bubbles: true }));
}
} catch (error) {
alert(`Failed to load demo data: ${error}`);
} finally {
setIsLoadingDemoData(false);
}
}
return (
<>
<form className="mb-4" onSubmit={handleSubmit}>
<div className="formentry">
<label className="form-label d-block">
Upload <i>.cs</i> File of the Helical Refinement Job
</label>
<input
id="FileInput"
className="form-control d-block"
ref={fileInputRef}
type="file"
accept=".cs"
onChange={handleFileChange}
required
disabled={isDisabled}
/>
{selectedFile &&
<strong className="d-block" style={{color: "red"}}>
File: {selectedFile.name} <br/>
Size: {(selectedFile.size / 1024).toFixed(2)} KB
</strong>
}
</div>
<div className="formentry">
<label htmlFor="TiltInput" className="form-label d-block">
Micrograph Tilting (°)
</label>
<input
id="TiltInput"
className="form-control d-block"
name="tilt"
value={formData.tilt}
onChange={handleInputChange}
required
placeholder="Ensure the sign of the tilt is correct."
data-tooltip-id="TiltInputTooltip"
disabled={isDisabled}
/>
<Tooltip
id="TiltInputTooltip"
content="Please note that the sign of the tilt will be double-checked during analysis via defocus fitting. You may adjust the sign in the next run if needed."
place="right"
variant="dark"
/>
</div>
<div className="formentry">
<label htmlFor="NumThresholdInput" className="form-label d-block">
Fibril Minimum Particle Count Threshold
</label>
<input
id="NumThresholdInput"
className="form-control d-block"
name="num_threshold"
value={formData.num_threshold}
onChange={handleInputChange}
data-tooltip-id="NumThresholdInputTooltip"
disabled={isDisabled}
/>
<Tooltip
id="NumThresholdInputTooltip"
content="Fibrils containing fewer particles than this threshold will be ignored during analysis."
place="right"
variant="dark"
/>
</div>
<div className="formentry">
<label htmlFor="EntropyThresholdInput" className="form-label d-block">
Fibril Maximum Particle Entropy Threshold
</label>
<input
id="EntropyThresholdInput"
className="form-control d-block"
name="entropy_threshold"
value={formData.entropy_threshold}
onChange={handleInputChange}
data-tooltip-id="entropy_threshold_tooltip"
disabled={isDisabled}
/>
<Tooltip
id="entropy_threshold_tooltip"
content="Fibrils made up of particles whose polarity entropy exceeds this threshold will be excluded from the analysis."
place="right"
variant="dark"
/>
</div>
<div className="formentry mb-4">
<label htmlFor="n_plots" className="form-label d-block">
Number of Fibrils to Analyze
</label>
<input
id="n_plots"
className="form-control d-block"
name="n_plots"
value={formData.n_plots}
onChange={handleInputChange}
disabled={isDisabled}
/>
</div>
<button className="btn btn-primary w-100" type="submit" disabled={isDisabled}>
{statusText}
</button>
</form>
<button className="btn btn-primary w-100 mb-4" onClick={handleLoadDemoData} disabled={isDisabled}>
{isLoadingDemoData ? 'Loading...' : 'Load Demo'}
</button>
<div className="d-flex justify-content-center gap-2">
<a href="https://doi.org/10.1101/2025.09.30.679555" target="_blank" rel="noopener noreferrer" className="btn btn-secondary w-50">Read/Cite Paper</a>
<a href="https://smart.org.cn/en" target="_blank" rel="noopener noreferrer" className="btn btn-secondary w-50">About Us</a>
</div>
</>
);
}
export default UploadForm;