Browse Source

Merge pull request #138 from meriadec/master

Prevent unnecessary re-renders on Breadcrumb in send modal
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
bafc705930
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      src/components/Breadcrumb/index.js
  2. 22
      src/components/modals/Send.js
  3. 6
      static/i18n/en/translation.yml
  4. 6
      static/i18n/fr/translation.yml

49
src/components/Breadcrumb/index.js

@ -1,6 +1,6 @@
// @flow // @flow
import React, { Fragment } from 'react' import React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -71,26 +71,31 @@ type Props = {
currentStep: number | string, currentStep: number | string,
} }
const Breadcrumb = ({ items, currentStep }: Props) => ( class Breadcrumb extends PureComponent<Props> {
<BreadcrumbWrapper> render() {
{items.map((item, i) => { const { items, currentStep } = this.props
const active = i < parseInt(currentStep, 10) return (
const start = i === 0 <BreadcrumbWrapper>
return ( {items.map((item, i) => {
<Fragment const active = i < parseInt(currentStep, 10)
key={i} // eslint-disable-line react/no-array-index-key const start = i === 0
> return (
{!start && <BreadcrumbSeparator active={active} />} <Fragment
<BreadcrumbStep active={active}> key={i} // eslint-disable-line react/no-array-index-key
<BreadcrumbNumberWrapper> >
<BreadcrumbNumber active={active}>{i + 1}</BreadcrumbNumber> {!start && <BreadcrumbSeparator active={active} />}
</BreadcrumbNumberWrapper> <BreadcrumbStep active={active}>
<Box fontSize={3}>{item.label}</Box> <BreadcrumbNumberWrapper>
</BreadcrumbStep> <BreadcrumbNumber active={active}>{i + 1}</BreadcrumbNumber>
</Fragment> </BreadcrumbNumberWrapper>
) <Box fontSize={3}>{item.label}</Box>
})} </BreadcrumbStep>
</BreadcrumbWrapper> </Fragment>
) )
})}
</BreadcrumbWrapper>
)
}
}
export default Breadcrumb export default Breadcrumb

22
src/components/modals/Send.js

@ -99,6 +99,16 @@ class Send extends PureComponent<Props, State> {
...defaultState, ...defaultState,
} }
componentWillMount() {
const { t } = this.props
this._items = [
{ label: t('sendModal.Amount') },
{ label: t('sendModal.Summary') },
{ label: t('sendModal.SecureValidation') },
{ label: t('sendModal.Confirmation') },
]
}
getStepProps(data: any) { getStepProps(data: any) {
const { inputValue, step } = this.state const { inputValue, step } = this.state
const { t } = this.props const { t } = this.props
@ -127,6 +137,8 @@ class Send extends PureComponent<Props, State> {
} }
} }
_items = []
handleChangeInput = (key: $Keys<InputValue>) => (value: $Values<InputValue>) => handleChangeInput = (key: $Keys<InputValue>) => (value: $Values<InputValue>) =>
this.setState(prev => ({ this.setState(prev => ({
inputValue: { inputValue: {
@ -158,15 +170,7 @@ class Send extends PureComponent<Props, State> {
return ( return (
<Fragment> <Fragment>
<ModalBody p={3}> <ModalBody p={3}>
<Breadcrumb <Breadcrumb currentStep={step} items={this._items} />
currentStep={step}
items={[
{ label: 'Amount' },
{ label: 'Summary' },
{ label: 'Secure validation' },
{ label: 'Confirmation' },
]}
/>
</ModalBody> </ModalBody>
<ModalBody onClose={onClose}> <ModalBody onClose={onClose}>
<Step {...this.getStepProps(data)} /> <Step {...this.getStepProps(data)} />

6
static/i18n/en/translation.yml

@ -66,3 +66,9 @@ update:
IsUnlocked: IsUnlocked:
password: Password password: Password
sendModal:
Amount: Amount
Summary: Summary
SecureValidation: Secure validation
Confirmation: Confirmation

6
static/i18n/fr/translation.yml

@ -66,3 +66,9 @@ update:
IsUnlocked: IsUnlocked:
password: Mot de passe password: Mot de passe
sendModal:
Amount: Montant
Summary: Résumé
SecureValidation: Validation sécurisée
Confirmation: Confirmation

Loading…
Cancel
Save