-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix - performances (reselect) on homepage.
feat - TextArea debounced
- Loading branch information
Showing
11 changed files
with
245 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/blockchain-wallet-v4-frontend/src/components/Form/TextAreaDebounced/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
import { equals } from 'ramda' | ||
import { Text, TextAreaInput } from 'blockchain-info-components' | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
align-items: flex-start; | ||
width: 100%; | ||
` | ||
const Error = styled(Text)` | ||
position: absolute; | ||
display: block; | ||
height: 15px; | ||
top: ${props => props.errorBottom ? '40px' : '-20px'}; | ||
right: 0; | ||
` | ||
const getErrorState = (meta) => { | ||
return meta.touched && meta.invalid ? 'invalid' : 'initial' | ||
} | ||
|
||
class TextAreaDebounced extends React.Component { | ||
static getDerivedStateFromProps (nextProps, prevState) { | ||
if (!equals(nextProps.input.value, prevState)) { | ||
return { value: nextProps.input.value } | ||
} | ||
return null | ||
} | ||
|
||
constructor (props) { | ||
super(props) | ||
this.state = { value: props.input.value } | ||
this.timeout = undefined | ||
this.handleChange = this.handleChange.bind(this) | ||
this.handleBlur = this.handleBlur.bind(this) | ||
this.handleFocus = this.handleFocus.bind(this) | ||
} | ||
|
||
componentWillUnmount () { | ||
clearTimeout(this.timeout) | ||
} | ||
|
||
handleChange (e) { | ||
e.preventDefault() | ||
console.log('lol') | ||
const value = e.target.value | ||
this.setState({ value }) | ||
if (this.timeout) clearTimeout(this.timeout) | ||
this.timeout = setTimeout(() => { | ||
console.log('LOL') | ||
this.props.input.onChange(value) | ||
}, 500) | ||
} | ||
|
||
handleBlur () { | ||
this.props.input.onBlur(this.state.value) | ||
} | ||
|
||
handleFocus () { | ||
this.props.input.onFocus(this.state.value) | ||
} | ||
|
||
render () { | ||
const { meta, disabled, placeholder, rows, ...rest } = this.props | ||
const errorState = getErrorState(meta) | ||
|
||
return ( | ||
<Container> | ||
<TextAreaInput | ||
value={this.state.value} | ||
errorState={errorState} | ||
disabled={disabled} | ||
placeholder={placeholder} | ||
rows={rows} | ||
onChange={this.handleChange} | ||
onFocus={this.handleFocus} | ||
onBlur={this.handleBlur} | ||
{...rest} | ||
/> | ||
{meta.touched && meta.error && <Error size='12px' weight={300} color='error'>{meta.error}</Error>} | ||
</Container> | ||
) | ||
} | ||
} | ||
|
||
export default TextAreaDebounced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
packages/blockchain-wallet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import { Remote } from 'blockchain-wallet-v4/src' | ||
import { selectors } from 'data' | ||
import { lift } from 'ramda' | ||
import { createDeepEqualSelector } from 'services/ReselectHelper' | ||
|
||
export const getData = (state) => { | ||
const ethContextR = selectors.core.kvStore.ethereum.getContext(state) | ||
const bchContextR = Remote.of(selectors.core.kvStore.bch.getContext(state)) | ||
const btcContextR = Remote.of(selectors.core.wallet.getWalletContext(state)) | ||
|
||
const path = state.router.location.pathname | ||
const transform = lift((btcContext, ethContext, bchContext) => ({btcContext, ethContext, bchContext, path})) | ||
return transform(btcContextR, ethContextR, bchContextR) | ||
} | ||
export const getData = createDeepEqualSelector( | ||
[ | ||
selectors.core.wallet.getWalletContext, | ||
selectors.core.kvStore.bch.getContext, | ||
selectors.core.kvStore.ethereum.getContext, | ||
selectors.router.getPathname | ||
], | ||
(btcContext, bchContext, ethContextR, path) => { | ||
const transform = (ethContext) => ({ | ||
btcContext, | ||
ethContext, | ||
bchContext, | ||
path | ||
}) | ||
return ethContextR.map(transform) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 2 additions & 7 deletions
9
packages/blockchain-wallet-v4-frontend/src/scenes/Home/ActivityList/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.