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

more UI updates

This commit is contained in:
Bogdan Fazakas 2022-09-20 10:32:17 +03:00
parent 45eea31d66
commit ac4ed257af
4 changed files with 105 additions and 25 deletions

View File

@ -0,0 +1,49 @@
.info {
border-radius: var(--border-radius);
padding: calc(var(--spacer) / 2);
border: 1px solid var(--border-color);
background-color: var(--background-highlight);
position: relative;
}
.info ul {
margin: 0;
}
.info li {
display: inline-block;
font-size: var(--font-size-small);
margin-right: calc(var(--spacer) / 2);
color: var(--color-secondary);
}
.info li.success {
color: var(--brand-alert-green);
}
.url {
margin: 0;
font-size: var(--font-size-base);
line-height: var(--line-height);
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
padding-right: calc(var(--spacer) / 2);
}
.warning {
margin-top: calc(var(--spacer) / 3);
margin-left: 0;
}
.removeButton {
cursor: pointer;
border: none;
position: absolute;
top: -0.2rem;
right: 0;
font-size: var(--font-size-h3);
cursor: pointer;
color: var(--font-color-text);
background-color: transparent;
}

View File

@ -0,0 +1,24 @@
import React, { ReactElement } from 'react'
import styles from './Info.module.css'
export default function ImageInfo({
image,
tag,
handleClose
}: {
image: string
tag: string
handleClose(): void
}): ReactElement {
return (
<div className={styles.info}>
<h3 className={styles.url}>{`${image}:${tag}`}</h3>
<ul>
<li className={styles.success}> Image found</li>
</ul>
<button className={styles.removeButton} onClick={handleClose}>
&times;
</button>
</div>
)
}

View File

@ -7,11 +7,14 @@ import { LoggerInstance } from '@oceanprotocol/lib'
import { toast } from 'react-toastify'
import axios from 'axios'
import isUrl from 'is-url-superb'
import ImageInfo from './Info'
export default function FilesInput(props: InputProps): ReactElement {
export default function ContainerInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name)
const [isLoading, setIsLoading] = useState(false)
const { values, setFieldError } = useFormikContext<FormPublishData>()
const [isValid, setIsValid] = useState(false)
const { values, setFieldError, setFieldValue } =
useFormikContext<FormPublishData>()
async function getContainerChecksum(
image: string,
@ -52,17 +55,16 @@ export default function FilesInput(props: InputProps): ReactElement {
setIsLoading(true)
if (!isUrl(container, { lenient: false })) {
const parsedContainerValue = container.split(':')
const checksum = await getContainerChecksum(
parsedContainerValue[0],
parsedContainerValue[1]
)
values.metadata.dockerImageCustom = parsedContainerValue[0]
values.metadata.dockerImageCustomTag = parsedContainerValue[1]
const image = parsedContainerValue[0]
const tag = parsedContainerValue[1]
const checksum = await getContainerChecksum(image, tag)
setFieldValue('metadata.dockerImageCustom', image)
setFieldValue('metadata.dockerImageCustomTag', tag)
if (checksum) {
values.metadata.dockerImageCustomChecksum = checksum
setFieldValue('metadata.dockerImageCustomChecksum', checksum)
setIsValid(true)
}
} else {
console.log('open input modal')
}
} catch (error) {
setFieldError(`${field.name}[0].url`, error.message)
@ -73,26 +75,31 @@ export default function FilesInput(props: InputProps): ReactElement {
}
function handleClose() {
helpers.setValue(meta.initialValue)
setFieldValue('metadata.dockerImageCustom', '')
setFieldValue('metadata.dockerImageCustomTag', '')
setFieldValue('metadata.dockerImageCustomChecksum', '')
setIsValid(false)
helpers.setTouched(false)
}
return (
<>
<UrlInput
submitText="Check"
{...props}
name={`${field.name}[0].url`}
checkUrl={false}
isLoading={isLoading}
handleButtonClick={handleValidation}
/>
{/* {field?.value?.[0]?.valid === true ? (
<FileInfo file={field.value[0]} handleClose={handleClose} />
{isValid ? (
<ImageInfo
image={values.metadata.dockerImageCustom}
tag={values.metadata.dockerImageCustomTag}
handleClose={handleClose}
/>
) : (
)} */}
<UrlInput
submitText="Use"
{...props}
name={`${field.name}[0].url`}
checkUrl={false}
isLoading={isLoading}
handleButtonClick={handleValidation}
/>
)}
</>
)
}

View File

@ -129,7 +129,7 @@ export default function MetadataFields(): ReactElement {
)}
component={Input}
name="metadata.dockerImageCustomChecksum"
disabled
disabled={values.metadata.dockerImageCustomChecksum !== null}
/>
<Field
{...getFieldContent(