1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 09:44:53 +01:00

Merge branch 'fix/490' into main

This commit is contained in:
Dimo Dzhurenov 2021-04-21 17:31:07 +03:00
commit e21780530a
2 changed files with 12 additions and 2 deletions

View File

@ -27,7 +27,7 @@ export default function FileInput({
<Button <Button
style="primary" style="primary"
size="small" size="small"
onClick={(e: React.SyntheticEvent) => handleButtonClick(e, field.value)} onClick={(e: React.SyntheticEvent) => e.preventDefault()}
disabled={!field.value} disabled={!field.value}
> >
{isLoading ? <Loader /> : 'Add File'} {isLoading ? <Loader /> : 'Add File'}

View File

@ -14,7 +14,7 @@ export default function FilesInput(props: InputProps): ReactElement {
const [fileUrl, setFileUrl] = useState<string>() const [fileUrl, setFileUrl] = useState<string>()
const { config } = useOcean() const { config } = useOcean()
useEffect(() => { function loadFileInfo() {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
async function validateUrl() { async function validateUrl() {
@ -33,11 +33,16 @@ export default function FilesInput(props: InputProps): ReactElement {
setIsLoading(false) setIsLoading(false)
} }
} }
fileUrl && validateUrl() fileUrl && validateUrl()
return () => { return () => {
source.cancel() source.cancel()
} }
}
useEffect(() => {
loadFileInfo()
}, [fileUrl, config.providerUri]) }, [fileUrl, config.providerUri])
async function handleButtonClick(e: React.SyntheticEvent, url: string) { async function handleButtonClick(e: React.SyntheticEvent, url: string) {
@ -48,6 +53,11 @@ export default function FilesInput(props: InputProps): ReactElement {
// File example 'https://oceanprotocol.com/tech-whitepaper.pdf' // File example 'https://oceanprotocol.com/tech-whitepaper.pdf'
e.preventDefault() e.preventDefault()
// In the case when the user re-add the same URL after it was removed (by accident or intentionally)
if (fileUrl === url) {
loadFileInfo()
}
setFileUrl(url) setFileUrl(url)
} }