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

change publish type from data to dataset

This commit is contained in:
Bogdan Fazakas 2021-02-16 16:47:07 +02:00
parent 18cd6b6f01
commit 4088a790fb
2 changed files with 22 additions and 17 deletions

View File

@ -5,12 +5,13 @@ import Button from '../../atoms/Button'
const cx = classNames.bind(styles) const cx = classNames.bind(styles)
const publishTypes = [ export const TypeOfPublish = {
{ display: 'data', value: 'data' }, dataset: 'dataset',
{ display: 'algorithms', value: 'algorithms' } algorithm: 'algorithm'
] } as const
type TypeOfPublish = typeof TypeOfPublish[keyof typeof TypeOfPublish]
export default function PublishType({ export function PublishType({
type, type,
setType setType
}: { }: {
@ -18,14 +19,14 @@ export default function PublishType({
setType: React.Dispatch<React.SetStateAction<string>> setType: React.Dispatch<React.SetStateAction<string>>
}): ReactElement { }): ReactElement {
useEffect(() => { useEffect(() => {
setType(publishTypes[0].value) setType(TypeOfPublish.dataset)
}, []) }, [])
return ( return (
<div> <div>
{publishTypes.map((e, index) => { {Object.keys(TypeOfPublish).map((key, index) => {
const tabElement = cx({ const tabElement = cx({
[styles.selected]: e.value === type, [styles.selected]: key === type,
[styles.tabElement]: true [styles.tabElement]: true
}) })
return ( return (
@ -35,10 +36,10 @@ export default function PublishType({
key={index} key={index}
className={tabElement} className={tabElement}
onClick={async () => { onClick={async () => {
setType(e.value) setType(key)
}} }}
> >
{e.display} {key}
</Button> </Button>
) )
})} })}

View File

@ -4,7 +4,7 @@ import { usePublish, useOcean } from '@oceanprotocol/react'
import styles from './index.module.css' import styles from './index.module.css'
import FormPublish from './FormPublish' import FormPublish from './FormPublish'
import FormAlgoPublish from './FormAlgoPublish' import FormAlgoPublish from './FormAlgoPublish'
import PublishType from './PublishType' import { PublishType, TypeOfPublish } from './PublishType'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
import { FormContent } from '../../../@types/Form' import { FormContent } from '../../../@types/Form'
import { initialValues, validationSchema } from '../../../models/FormPublish' import { initialValues, validationSchema } from '../../../models/FormPublish'
@ -55,7 +55,7 @@ export default function PublishPage({
const hasFeedback = isLoading || error || success const hasFeedback = isLoading || error || success
useEffect(() => { useEffect(() => {
publishType === 'data' publishType === TypeOfPublish.dataset
? setTitle('Publishing Data Set') ? setTitle('Publishing Data Set')
: setTitle('Publishing Algorithm') : setTitle('Publishing Algorithm')
}, [publishType]) }, [publishType])
@ -136,17 +136,21 @@ export default function PublishPage({
return isInPurgatory && purgatoryData ? null : ( return isInPurgatory && purgatoryData ? null : (
<Formik <Formik
initialValues={ initialValues={
publishType === 'data' ? initialValues : initialValuesAlgorithm publishType === TypeOfPublish.dataset
? initialValues
: initialValuesAlgorithm
} }
initialStatus="empty" initialStatus="empty"
validationSchema={ validationSchema={
publishType === 'data' ? validationSchema : validationSchemaAlgorithm publishType === TypeOfPublish.dataset
? validationSchema
: validationSchemaAlgorithm
} }
onSubmit={async (values, { resetForm }) => { onSubmit={async (values, { resetForm }) => {
// move user's focus to top of screen // move user's focus to top of screen
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
// kick off publishing // kick off publishing
publishType === 'data' publishType === TypeOfPublish.dataset
? await handleSubmit(values, resetForm) ? await handleSubmit(values, resetForm)
: await handleAlgorithmSubmit(values, resetForm) : await handleAlgorithmSubmit(values, resetForm)
}} }}
@ -176,7 +180,7 @@ export default function PublishPage({
className={styles.alert} className={styles.alert}
/> />
<article className={styles.grid}> <article className={styles.grid}>
{publishType === 'data' ? ( {publishType === TypeOfPublish.dataset ? (
<FormPublish content={content.form} /> <FormPublish content={content.form} />
) : ( ) : (
<FormAlgoPublish content={contentAlgoPublish.form} /> <FormAlgoPublish content={contentAlgoPublish.form} />
@ -184,7 +188,7 @@ export default function PublishPage({
<aside> <aside>
<div className={styles.sticky}> <div className={styles.sticky}>
{publishType === 'data' ? ( {publishType === TypeOfPublish.dataset ? (
<MetadataPreview values={values} /> <MetadataPreview values={values} />
) : ( ) : (
<MetadataAlgorithmPreview values={values} /> <MetadataAlgorithmPreview values={values} />