1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 17:24:51 +01:00

refactor publish page for tab usage

This commit is contained in:
Matthias Kretschmann 2021-02-22 16:15:22 +01:00
parent 2f1bd399f8
commit 82a12a915d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 89 additions and 135 deletions

View File

@ -3,7 +3,6 @@ import styles from './index.module.css'
import Compute from './Compute' import Compute from './Compute'
import Consume from './Consume' import Consume from './Consume'
import { Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
import Tabs from '../../atoms/Tabs' import Tabs from '../../atoms/Tabs'
import { useOcean } from '@oceanprotocol/react' import { useOcean } from '@oceanprotocol/react'
import compareAsBN from '../../../utils/compareAsBN' import compareAsBN from '../../../utils/compareAsBN'

View File

@ -1,29 +0,0 @@
.tabElement,
button.tabElement,
.tabElement:hover,
.tabElement:active,
.tabElement:focus {
border: 1px solid var(--border-color);
text-transform: uppercase;
border-radius: var(--border-radius);
margin-right: calc(var(--spacer) / 6);
margin-bottom: calc(var(--spacer) / 6);
color: var(--color-secondary);
background: var(--background-body);
/* the only thing not possible to overwrite button style="text" with more specifity of selectors, so sledgehammer */
padding: calc(var(--spacer) / 5) !important;
}
.tabElement:hover,
.tabElement:focus {
color: var(--font-color-text);
background: inherit;
transform: none;
}
.tabElement.selected {
color: var(--background-body);
background: var(--font-color-text);
border-color: var(--background-body);
}

View File

@ -1,48 +0,0 @@
import React, { ReactElement, useEffect } from 'react'
import styles from './PublishType.module.css'
import classNames from 'classnames/bind'
import Button from '../../atoms/Button'
const cx = classNames.bind(styles)
export const TypeOfPublish = {
dataset: 'dataset',
algorithm: 'algorithm'
} as const
type TypeOfPublish = typeof TypeOfPublish[keyof typeof TypeOfPublish]
export function PublishType({
type,
setType
}: {
type: string
setType: React.Dispatch<React.SetStateAction<string>>
}): ReactElement {
useEffect(() => {
setType(TypeOfPublish.dataset)
}, [])
return (
<div>
{Object.keys(TypeOfPublish).map((key, index) => {
const tabElement = cx({
[styles.selected]: key === type,
[styles.tabElement]: true
})
return (
<Button
size="small"
style="text"
key={index}
className={tabElement}
onClick={async () => {
setType(key)
}}
>
{key}
</Button>
)
})}
</div>
)
}

View File

@ -1,3 +1,8 @@
.tabs div[class*='tabContent'] {
padding-left: 0;
padding-right: 0;
}
.grid { .grid {
display: grid; display: grid;
gap: calc(var(--spacer) * 1.5); gap: calc(var(--spacer) * 1.5);

View File

@ -4,9 +4,8 @@ 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, TypeOfPublish } from './PublishType'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
import { FormContent } from '../../../@types/Form' import Tabs from '../../atoms/Tabs'
import { initialValues, validationSchema } from '../../../models/FormPublish' import { initialValues, validationSchema } from '../../../models/FormPublish'
import { import {
initialValues as initialValuesAlgorithm, initialValues as initialValuesAlgorithm,
@ -27,15 +26,42 @@ import {
MetadataPublishFormAlgorithm MetadataPublishFormAlgorithm
} from '../../../@types/MetaData' } from '../../../@types/MetaData'
import { useUserPreferences } from '../../../providers/UserPreferences' import { useUserPreferences } from '../../../providers/UserPreferences'
import { Logger, Metadata } from '@oceanprotocol/lib' import { Logger, Metadata, MetadataMain } from '@oceanprotocol/lib'
import { Persist } from '../../atoms/FormikPersist' import { Persist } from '../../atoms/FormikPersist'
import Debug from './Debug' import Debug from './Debug'
import Alert from '../../atoms/Alert' import Alert from '../../atoms/Alert'
import MetadataFeedback from '../../molecules/MetadataFeedback' import MetadataFeedback from '../../molecules/MetadataFeedback'
import Button from '../../atoms/Button'
const formName = 'ocean-publish-form' const formName = 'ocean-publish-form'
function TabContent({
publishType,
values
}: {
publishType: MetadataMain['type']
values:
| Partial<MetadataPublishFormDataset>
| Partial<MetadataPublishFormAlgorithm>
}) {
return (
<article className={styles.grid}>
{publishType === 'dataset' ? <FormPublish /> : <FormAlgoPublish />}
<aside>
<div className={styles.sticky}>
{publishType === 'dataset' ? (
<MetadataPreview values={values} />
) : (
<MetadataAlgorithmPreview values={values} />
)}
<Web3Feedback />
</div>
</aside>
</article>
)
}
export default function PublishPage({ export default function PublishPage({
content content
}: { }: {
@ -48,12 +74,12 @@ export default function PublishPage({
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
const [did, setDid] = useState<string>() const [did, setDid] = useState<string>()
const [publishType, setPublishType] = useState<string>() const [publishType, setPublishType] = useState<MetadataMain['type']>()
const hasFeedback = isLoading || error || success const hasFeedback = isLoading || error || success
useEffect(() => { useEffect(() => {
publishType === TypeOfPublish.dataset publishType === 'dataset'
? setTitle('Publishing Data Set') ? setTitle('Publishing Data Set')
: setTitle('Publishing Algorithm') : setTitle('Publishing Algorithm')
}, [publishType]) }, [publishType])
@ -137,26 +163,34 @@ export default function PublishPage({
return isInPurgatory && purgatoryData ? null : ( return isInPurgatory && purgatoryData ? null : (
<Formik <Formik
initialValues={ initialValues={
publishType === TypeOfPublish.dataset publishType === 'dataset' ? initialValues : initialValuesAlgorithm
? initialValues
: initialValuesAlgorithm
} }
initialStatus="empty" initialStatus="empty"
validationSchema={ validationSchema={
publishType === TypeOfPublish.dataset publishType === 'dataset' ? validationSchema : validationSchemaAlgorithm
? 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 === TypeOfPublish.dataset publishType === 'dataset'
? await handleSubmit(values, resetForm) ? await handleSubmit(values, resetForm)
: await handleAlgorithmSubmit(values, resetForm) : await handleAlgorithmSubmit(values, resetForm)
}} }}
> >
{({ values }) => ( {({ values }) => {
const tabs = [
{
title: 'Data Set',
content: <TabContent values={values} publishType={publishType} />
},
{
title: 'Algorithm',
content: <TabContent values={values} publishType={publishType} />
}
]
return (
<> <>
<Persist name={formName} ignoreFields={['isSubmitting']} /> <Persist name={formName} ignoreFields={['isSubmitting']} />
@ -174,36 +208,29 @@ export default function PublishPage({
/> />
) : ( ) : (
<> <>
<PublishType type={publishType} setType={setPublishType} />
<Alert <Alert
text={content.warning} text={content.warning}
state="info" state="info"
className={styles.alert} className={styles.alert}
/> />
<article className={styles.grid}>
{publishType === TypeOfPublish.dataset ? (
<FormPublish />
) : (
<FormAlgoPublish />
)}
<aside> <div className={styles.tabs}>
<div className={styles.sticky}> <Tabs
{publishType === TypeOfPublish.dataset ? ( items={tabs}
<MetadataPreview values={values} /> handleTabChange={(title) =>
) : ( setPublishType(
<MetadataAlgorithmPreview values={values} /> title.toLowerCase().replace(' ', '') as any
)} )
<Web3Feedback /> }
/>
</div> </div>
</aside>
</article>
</> </>
)} )}
{debug === true && <Debug values={values} />} {debug === true && <Debug values={values} />}
</> </>
)} )
}}
</Formik> </Formik>
) )
} }