1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
This commit is contained in:
mihaisc 2020-08-27 16:13:31 +03:00
parent dfccd101f7
commit 2daab8b175
3 changed files with 51 additions and 48 deletions

View File

@ -1,71 +1,71 @@
import * as React from 'react';
import { FormikProps, connect } from 'formik';
import debounce from 'lodash.debounce';
import omit from 'lodash.omit';
import isEqual from 'react-fast-compare';
import * as React from 'react'
import { FormikProps, connect } from 'formik'
import debounce from 'lodash.debounce'
import omit from 'lodash.omit'
import isEqual from 'react-fast-compare'
export interface PersistProps {
name: string;
ignoreFields?: string[];
debounce?: number;
isSessionStorage?: boolean;
name: string
ignoreFields?: string[]
debounce?: number
isSessionStorage?: boolean
}
class PersistImpl extends React.Component<
PersistProps & { formik: FormikProps<any> },
{}
any
> {
static defaultProps = {
debounce: 300,
};
saveForm = debounce((data: FormikProps<{}>) => {
const dataToSave = this.omitIgnoredFields(data);
console.log("data tosave",dataToSave)
if (this.props.isSessionStorage) {
window.sessionStorage.setItem(
this.props.name,
JSON.stringify(dataToSave)
);
} else {
window.localStorage.setItem(this.props.name, JSON.stringify(dataToSave));
debounce: 300
}
}, this.props.debounce);
omitIgnoredFields = (data: FormikProps<{}>) => {
const { ignoreFields } = this.props;
saveForm = debounce((data: FormikProps<any>) => {
const dataToSave = this.omitIgnoredFields(data)
console.log('data tosave', dataToSave)
if (this.props.isSessionStorage) {
window.sessionStorage.setItem(this.props.name, JSON.stringify(dataToSave))
} else {
window.localStorage.setItem(this.props.name, JSON.stringify(dataToSave))
}
}, this.props.debounce)
omitIgnoredFields = (data: FormikProps<any>) => {
const { ignoreFields } = this.props
console.log('omit fiel', ignoreFields)
const { values, touched, errors } = data;
const { values, touched, errors } = data
console.log( "vale", values, omit(values, ignoreFields))
console.log('vale', values, omit(values, ignoreFields))
return ignoreFields
? omit({
? omit(
{
...data,
values: omit(values, ignoreFields),
touched: omit(touched, ignoreFields),
errors: omit(errors, ignoreFields),
}, ignoreFields)
: data;
};
errors: omit(errors, ignoreFields)
},
ignoreFields
)
: data
}
componentDidUpdate(prevProps: PersistProps & { formik: FormikProps<any> }) {
if (!isEqual(prevProps.formik, this.props.formik)) {
this.saveForm(this.props.formik);
this.saveForm(this.props.formik)
}
}
componentDidMount() {
const maybeState = this.props.isSessionStorage
? window.sessionStorage.getItem(this.props.name)
: window.localStorage.getItem(this.props.name);
: window.localStorage.getItem(this.props.name)
if (maybeState && maybeState !== null) {
this.props.formik.setFormikState(JSON.parse(maybeState));
this.props.formik.setFormikState(JSON.parse(maybeState))
}
}
render(): any {
return null;
return null
}
}
export const Persist = connect<PersistProps, any>(PersistImpl);
export const Persist = connect<PersistProps, any>(PersistImpl)

View File

@ -12,10 +12,9 @@ export default function PublishForm({
content,
publishStepText,
isLoading
}: {
content: FormContent,
publishStepText?:string,
content: FormContent
publishStepText?: string
isLoading: boolean
}): ReactElement {
const { ocean, account } = useOcean()

View File

@ -104,7 +104,11 @@ export default function PublishPage({
>
{({ values }) => (
<>
<PublishForm content={content.form} isLoading={isLoading} publishStepText={publishStepText} />
<PublishForm
content={content.form}
isLoading={isLoading}
publishStepText={publishStepText}
/>
<aside>
<div className={styles.sticky}>
<Preview values={values} />