add loading state to UploadMod.jsx

This commit is contained in:
Jan Naahs 2020-10-24 14:16:02 +02:00
parent f34c630ce1
commit 5836480529

View File

@ -9,13 +9,16 @@ const UploadMod = ({refetchInstalledMods}) => {
const defaultFileName = 'Select File ...'
const [fileName, setFileName] = useState(defaultFileName);
const {register, handleSubmit } = useForm();
const [isUploading, setIsUploading] = useState(false);
const onSubmit = (data, e) => {
setIsUploading(true)
modsResource.upload(data.mod_file[0])
.then(refetchInstalledMods)
.finally(() => {
e.target.reset()
setFileName(defaultFileName)
setIsUploading(false);
})
}
@ -32,7 +35,7 @@ const UploadMod = ({refetchInstalledMods}) => {
type="file"/>
<div className="px-2 py-2">{fileName}</div>
</div>
<Button isSubmit={true}>Upload</Button>
<Button isLoading={isUploading} isSubmit={true}>Upload</Button>
</form>
)
}