feat(frontend): add upload icon
This commit is contained in:
@@ -5,15 +5,32 @@ type props = {
|
||||
dataSend: React.MouseEventHandler<HTMLButtonElement>;
|
||||
handleDownload: React.MouseEventHandler<HTMLButtonElement>;
|
||||
downloadable: boolean;
|
||||
progress: number
|
||||
progress: number;
|
||||
uploading: boolean;
|
||||
}
|
||||
|
||||
const ExportWidget = ({dataSend, handleDownload, downloadable, progress}: props) => {
|
||||
const Spinner = () => (
|
||||
<svg
|
||||
className="animate-spin h-4 w-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
const ExportWidget = ({dataSend, handleDownload, downloadable, progress, uploading}: props) => {
|
||||
return (
|
||||
<div className={"flex flex-col gap-3"}>
|
||||
<BlueButton
|
||||
onClick={dataSend}>
|
||||
Export
|
||||
onClick={dataSend}
|
||||
disabled={uploading}
|
||||
className={uploading ? "opacity-60 cursor-not-allowed flex items-center justify-center gap-2" : ""}
|
||||
>
|
||||
{uploading && <Spinner />}
|
||||
{uploading ? "Uploading..." : "Export"}
|
||||
</BlueButton>
|
||||
|
||||
<div className="h-10 flex items-center">
|
||||
@@ -33,4 +50,4 @@ const ExportWidget = ({dataSend, handleDownload, downloadable, progress}: props)
|
||||
)
|
||||
}
|
||||
|
||||
export default ExportWidget;
|
||||
export default ExportWidget;
|
||||
|
||||
@@ -34,6 +34,7 @@ const ClipEdit = () => {
|
||||
});
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [downloadable, setDownloadable] = useState(false);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -59,7 +60,10 @@ const ClipEdit = () => {
|
||||
};
|
||||
|
||||
const sendData = async () => {
|
||||
if (!localFile) return;
|
||||
if (!localFile || uploading) return;
|
||||
|
||||
setUploading(true);
|
||||
setError(null);
|
||||
|
||||
let jobId: string;
|
||||
try {
|
||||
@@ -67,6 +71,7 @@ const ClipEdit = () => {
|
||||
setUploadedId(jobId);
|
||||
} catch (err: unknown) {
|
||||
setError(`Failed to start compression: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
||||
setUploading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,14 +86,17 @@ const ClipEdit = () => {
|
||||
if (job.state === 'FAILED') {
|
||||
setError(`Compression failed: ${job.errorOutput ?? 'Unknown error'}`);
|
||||
clearInterval(intervalId);
|
||||
setUploading(false);
|
||||
} else if (job.isComplete) {
|
||||
clearInterval(intervalId);
|
||||
setDownloadable(true);
|
||||
setUploading(false);
|
||||
}
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
setError(`Failed to fetch progress: ${err.message}`);
|
||||
clearInterval(intervalId);
|
||||
setUploading(false);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -166,6 +174,7 @@ const ClipEdit = () => {
|
||||
handleDownload={handleDownload}
|
||||
downloadable={downloadable}
|
||||
progress={progress}
|
||||
uploading={uploading}
|
||||
/>
|
||||
</Box>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user