1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

adding placeholder file url in edit form

This commit is contained in:
EnzoVezzaro 2022-08-15 09:28:26 -04:00
parent 95199054f8
commit 8587535a44
3 changed files with 30 additions and 5 deletions

View File

@ -31,6 +31,10 @@
padding-right: calc(var(--spacer) / 2);
}
.hideUrl {
filter: blur(0.2rem);
}
.warning {
margin-top: calc(var(--spacer) / 3);
margin-left: 0;

View File

@ -6,18 +6,22 @@ import { FileInfo as FileInfoData } from '@oceanprotocol/lib'
export default function FileInfo({
file,
handleClose
handleClose,
hideUrl
}: {
file: FileInfoData
handleClose(): void
hideUrl?: boolean
}): ReactElement {
const contentTypeCleaned = file.contentType
? cleanupContentType(file.contentType)
: null
return (
<div className={styles.info}>
<h3 className={styles.url}>{file.url}</h3>
<div className={`${styles.info}`}>
<h3 className={`${styles.url} ${hideUrl ? styles.hideUrl : null}`}>
{file.url}
</h3>
<ul>
<li className={styles.success}> URL confirmed</li>
{file.contentLength && <li>{prettySize(+file.contentLength)}</li>}

View File

@ -3,7 +3,7 @@ import { useField, useFormikContext } from 'formik'
import FileInfo from './Info'
import UrlInput from '../URLInput'
import { InputProps } from '@shared/FormInput'
import { getFileUrlInfo } from '@utils/provider'
import { getFileDidInfo, getFileUrlInfo } from '@utils/provider'
import { FormPublishData } from 'src/components/Publish/_types'
import { LoggerInstance } from '@oceanprotocol/lib'
import { useAsset } from '@context/Asset'
@ -11,6 +11,7 @@ import { useAsset } from '@context/Asset'
export default function FilesInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name)
const [isLoading, setIsLoading] = useState(false)
const [hideUrl, setHideUrl] = useState(false)
const { values, setFieldError } = useFormikContext<FormPublishData>()
const { asset } = useAsset()
@ -50,13 +51,29 @@ export default function FilesInput(props: InputProps): ReactElement {
useEffect(() => {
if (field.name === 'links' && asset?.metadata?.links) {
handleValidation(null, asset.metadata.links[0])
} else if (field.name === 'files' && asset?.metadata?.links) {
getFileDidInfo(
asset?.id,
asset?.services[0]?.id,
asset?.services[0]?.serviceEndpoint
).then((fileDidInfo) => {
setHideUrl(true)
// setting placeholder for url file to avoid txs for the url file during initializing
helpers.setValue([
{ url: 'oceanprotocol.com/placeholder', ...fileDidInfo[0] }
])
})
}
}, [])
return (
<>
{field?.value?.[0]?.valid === true ? (
<FileInfo file={field.value[0]} handleClose={handleClose} />
<FileInfo
hideUrl={hideUrl}
file={field.value[0]}
handleClose={handleClose}
/>
) : (
<UrlInput
submitText="Validate"