mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-14 17:24:51 +01:00
format
This commit is contained in:
parent
dfccd101f7
commit
2daab8b175
@ -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,
|
||||
};
|
||||
debounce: 300
|
||||
}
|
||||
|
||||
saveForm = debounce((data: FormikProps<{}>) => {
|
||||
const dataToSave = this.omitIgnoredFields(data);
|
||||
console.log("data tosave",dataToSave)
|
||||
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)
|
||||
);
|
||||
window.sessionStorage.setItem(this.props.name, JSON.stringify(dataToSave))
|
||||
} else {
|
||||
window.localStorage.setItem(this.props.name, JSON.stringify(dataToSave));
|
||||
window.localStorage.setItem(this.props.name, JSON.stringify(dataToSave))
|
||||
}
|
||||
}, this.props.debounce);
|
||||
}, this.props.debounce)
|
||||
|
||||
omitIgnoredFields = (data: FormikProps<{}>) => {
|
||||
const { ignoreFields } = this.props;
|
||||
console.log('omit fiel',ignoreFields)
|
||||
const { values, touched, errors } = data;
|
||||
omitIgnoredFields = (data: FormikProps<any>) => {
|
||||
const { ignoreFields } = this.props
|
||||
console.log('omit fiel', ignoreFields)
|
||||
const { values, touched, errors } = data
|
||||
|
||||
console.log( "vale", values, omit(values, ignoreFields))
|
||||
console.log('vale', values, omit(values, ignoreFields))
|
||||
return ignoreFields
|
||||
? omit({
|
||||
...data,
|
||||
values: omit(values, ignoreFields),
|
||||
touched: omit(touched, ignoreFields),
|
||||
errors: omit(errors, ignoreFields),
|
||||
}, ignoreFields)
|
||||
: data;
|
||||
};
|
||||
? omit(
|
||||
{
|
||||
...data,
|
||||
values: omit(values, ignoreFields),
|
||||
touched: omit(touched, ignoreFields),
|
||||
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;
|
||||
render(): any {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const Persist = connect<PersistProps, any>(PersistImpl);
|
||||
export const Persist = connect<PersistProps, any>(PersistImpl)
|
||||
|
@ -12,11 +12,10 @@ export default function PublishForm({
|
||||
content,
|
||||
publishStepText,
|
||||
isLoading
|
||||
|
||||
}: {
|
||||
content: FormContent,
|
||||
publishStepText?:string,
|
||||
isLoading:boolean
|
||||
content: FormContent
|
||||
publishStepText?: string
|
||||
isLoading: boolean
|
||||
}): ReactElement {
|
||||
const { ocean, account } = useOcean()
|
||||
const {
|
||||
@ -34,7 +33,7 @@ export default function PublishForm({
|
||||
useEffect(() => {
|
||||
setErrors({})
|
||||
setTouched({})
|
||||
|
||||
|
||||
// setSubmitting(false)
|
||||
}, [])
|
||||
|
||||
@ -62,7 +61,7 @@ export default function PublishForm({
|
||||
<Button
|
||||
style="primary"
|
||||
type="submit"
|
||||
disabled={!ocean || !account || !isValid || status === 'empty' }
|
||||
disabled={!ocean || !account || !isValid || status === 'empty'}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
|
@ -20,7 +20,7 @@ export default function PublishPage({
|
||||
}): ReactElement {
|
||||
const { marketFeeAddress, marketFeeAmount } = useSiteMetadata()
|
||||
const { accountId, ocean } = useOcean()
|
||||
const { publish, publishError,isLoading,publishStepText } = usePublish()
|
||||
const { publish, publishError, isLoading, publishStepText } = usePublish()
|
||||
const navigate = useNavigate()
|
||||
|
||||
async function handleSubmit(
|
||||
@ -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} />
|
||||
|
Loading…
Reference in New Issue
Block a user