From dca5b9f56c519088d2c8c47192aa9ecf8ad10dd8 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 24 Feb 2021 13:32:15 +0200 Subject: [PATCH 1/2] fix persistance for both publish forms --- src/components/pages/Publish/index.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index 36664181e..fd9ddd030 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -73,6 +73,12 @@ export default function PublishPage({ const [error, setError] = useState() const [title, setTitle] = useState() const [did, setDid] = useState() + const [algoInitialValues, setAlgoInitialValues] = useState< + Partial + >(initialValuesAlgorithm) + const [datasetInitialValues, setdatasetInitialValues] = useState< + Partial + >(initialValues) const [publishType, setPublishType] = useState( 'dataset' ) @@ -164,7 +170,7 @@ export default function PublishPage({ return isInPurgatory && purgatoryData ? null : ( {({ values }) => { const tabs = [ @@ -225,9 +232,12 @@ export default function PublishPage({ + handleTabChange={(title) => { setPublishType(title.toLowerCase().replace(' ', '') as any) - } + title === 'Algorithm' + ? setdatasetInitialValues(values) + : setAlgoInitialValues(values) + }} /> )} From 90787e903161d24c21d60574319e430d0dc23ec4 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Thu, 25 Feb 2021 14:21:05 +0200 Subject: [PATCH 2/2] fixed reset form & cover flow where algorithm form is clear --- .../pages/Publish/FormAlgoPublish.tsx | 7 +++- src/components/pages/Publish/FormPublish.tsx | 6 +++- src/components/pages/Publish/index.tsx | 34 +++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/components/pages/Publish/FormAlgoPublish.tsx b/src/components/pages/Publish/FormAlgoPublish.tsx index 58490e121..9f11369ff 100644 --- a/src/components/pages/Publish/FormAlgoPublish.tsx +++ b/src/components/pages/Publish/FormAlgoPublish.tsx @@ -7,6 +7,8 @@ import Input from '../../atoms/Input' import Button from '../../atoms/Button' import { FormContent, FormFieldProps } from '../../../@types/Form' import { MetadataPublishFormAlgorithm } from '../../../@types/MetaData' +import { initialValues as initialValuesAlgorithm } from '../../../models/FormAlgoPublish' + import stylesIndex from './index.module.css' const query = graphql` @@ -115,7 +117,10 @@ export default function FormPublish(): ReactElement { const resetFormAndClearStorage = (e: FormEvent) => { e.preventDefault() - resetForm({ values: initialValues, status: 'empty' }) + resetForm({ + values: initialValuesAlgorithm as MetadataPublishFormAlgorithm, + status: 'empty' + }) setStatus('empty') } diff --git a/src/components/pages/Publish/FormPublish.tsx b/src/components/pages/Publish/FormPublish.tsx index 7433e573a..eafd635c8 100644 --- a/src/components/pages/Publish/FormPublish.tsx +++ b/src/components/pages/Publish/FormPublish.tsx @@ -7,6 +7,7 @@ import Input from '../../atoms/Input' import Button from '../../atoms/Button' import { FormContent, FormFieldProps } from '../../../@types/Form' import { MetadataPublishFormDataset } from '../../../@types/MetaData' +import { initialValues as initialValuesDataset } from '../../../models/FormAlgoPublish' import stylesIndex from './index.module.css' const query = graphql` @@ -73,7 +74,10 @@ export default function FormPublish(): ReactElement { const resetFormAndClearStorage = (e: FormEvent) => { e.preventDefault() - resetForm({ values: initialValues, status: 'empty' }) + resetForm({ + values: initialValuesDataset as MetadataPublishFormDataset, + status: 'empty' + }) setStatus('empty') } diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index fd9ddd030..38483705d 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -1,5 +1,5 @@ import React, { ReactElement, useState, useEffect } from 'react' -import { Formik } from 'formik' +import { Formik, FormikState } from 'formik' import { usePublish, useOcean } from '@oceanprotocol/react' import styles from './index.module.css' import FormPublish from './FormPublish' @@ -75,10 +75,20 @@ export default function PublishPage({ const [did, setDid] = useState() const [algoInitialValues, setAlgoInitialValues] = useState< Partial - >(initialValuesAlgorithm) + >( + (localStorage.getItem('ocean-publish-form-algorithms') && + (JSON.parse(localStorage.getItem('ocean-publish-form-algorithms')) + .initialValues as MetadataPublishFormAlgorithm)) || + initialValuesAlgorithm + ) const [datasetInitialValues, setdatasetInitialValues] = useState< Partial - >(initialValues) + >( + (localStorage.getItem('ocean-publish-form-datasets') && + (JSON.parse(localStorage.getItem('ocean-publish-form-datasets')) + .initialValues as MetadataPublishFormDataset)) || + initialValues + ) const [publishType, setPublishType] = useState( 'dataset' ) @@ -93,7 +103,9 @@ export default function PublishPage({ async function handleSubmit( values: Partial, - resetForm: () => void + resetForm: ( + nextState?: Partial>> + ) => void ): Promise { const metadata = transformPublishFormToMetadata(values) const timeout = mapTimeoutStringToSeconds(values.timeout) @@ -127,7 +139,10 @@ export default function PublishPage({ setSuccess( '🎉 Successfully published. 🎉 Now create a price on your data set.' ) - resetForm() + resetForm({ + values: initialValues as MetadataPublishFormDataset, + status: 'empty' + }) } catch (error) { setError(error.message) Logger.error(error.message) @@ -136,7 +151,9 @@ export default function PublishPage({ async function handleAlgorithmSubmit( values: Partial, - resetForm: () => void + resetForm: ( + nextState?: Partial>> + ) => void ): Promise { const metadata = transformPublishAlgorithmFormToMetadata(values) @@ -160,7 +177,10 @@ export default function PublishPage({ setSuccess( '🎉 Successfully published. 🎉 Now create a price for your algorithm.' ) - resetForm() + resetForm({ + values: initialValuesAlgorithm as MetadataPublishFormAlgorithm, + status: 'empty' + }) } catch (error) { setError(error.message) Logger.error(error.message)