Implementing Search Filter by Token
This commit is contained in:
parent
a655d3657b
commit
ad0211fda0
|
@ -102,10 +102,24 @@ type Props = {
|
||||||
tokens: List<Token>,
|
tokens: List<Token>,
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tokens extends React.Component<Props> {
|
type State = {
|
||||||
requestSearch = () => {
|
filter: string,
|
||||||
// eslint-disable-next-line
|
}
|
||||||
console.log("Filtering by name or symbol...")
|
|
||||||
|
const filterBy = (filter: string, tokens: List<Token>): List<Token> =>
|
||||||
|
tokens.filter((token: Token) => !filter || token.get('symbol').toLowerCase().startsWith(filter.toLowerCase()))
|
||||||
|
|
||||||
|
class Tokens extends React.Component<Props, State> {
|
||||||
|
state = {
|
||||||
|
filter: '',
|
||||||
|
}
|
||||||
|
|
||||||
|
onCancelSearch = () => {
|
||||||
|
this.setState(() => ({ filter: '' }))
|
||||||
|
}
|
||||||
|
|
||||||
|
onChangeSearchBar = (value) => {
|
||||||
|
this.setState(() => ({ filter: value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -117,6 +131,8 @@ class Tokens extends React.Component<Props> {
|
||||||
searchContainer: classes.searchContainer,
|
searchContainer: classes.searchContainer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filteredTokens = filterBy(this.state.filter, tokens)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Block className={classes.root}>
|
<Block className={classes.root}>
|
||||||
|
@ -132,20 +148,21 @@ class Tokens extends React.Component<Props> {
|
||||||
<SearchBar
|
<SearchBar
|
||||||
placeholder="Search by name or symbol"
|
placeholder="Search by name or symbol"
|
||||||
classes={searchClasses}
|
classes={searchClasses}
|
||||||
onRequestSearch={this.requestSearch}
|
|
||||||
searchIcon={<div />}
|
searchIcon={<div />}
|
||||||
|
onChange={this.onChangeSearchBar}
|
||||||
|
onCancelSearch={this.onCancelSearch}
|
||||||
/>
|
/>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Divider />
|
<Divider />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Button variant="contained" size="small" color="secondary" className={classes.add}>
|
<Button variant="contained" size="small" color="secondary" className={classes.add} disabled>
|
||||||
+ ADD CUSTOM TOKEN
|
+ ADD CUSTOM TOKEN
|
||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
<Hairline />
|
<Hairline />
|
||||||
</Block>
|
</Block>
|
||||||
<MuiList className={classes.list}>
|
<MuiList className={classes.list}>
|
||||||
{tokens.map((token: Token) => (
|
{filteredTokens.map((token: Token) => (
|
||||||
<ListItem key={token.get('address')} className={classes.token}>
|
<ListItem key={token.get('address')} className={classes.token}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<Img src={token.get('logoUrl')} height={28} alt={token.get('name')} />
|
<Img src={token.get('logoUrl')} height={28} alt={token.get('name')} />
|
||||||
|
|
Loading…
Reference in New Issue