This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validators search and details page update
- Loading branch information
1 parent
0b0f22c
commit aab4795
Showing
10 changed files
with
233 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
|
||
export type Identity = { | ||
avatarUrl: string, | ||
details: string, | ||
keybaseUsername: string, | ||
name: string, | ||
pubkey: string, | ||
verified: string, | ||
verifyUrl: string, | ||
website: string, | ||
}; | ||
|
||
export type UptimeItem = { | ||
creditsEarned: number, | ||
epoch: number, | ||
percentage: string, | ||
slotsInEpoch: number, | ||
}; | ||
|
||
export type Uptime = { | ||
lat: number, | ||
ts: number, | ||
votePubkey: string, | ||
uptime: UptimeItem[], | ||
}; | ||
|
||
export type Validator = { | ||
commission: number, | ||
coordinated: [number, number], | ||
gossip: string, | ||
identity: Identity, | ||
nodePubkey: string, | ||
stake: number, | ||
uptime: Uptime, | ||
}; |
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
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,40 +1,79 @@ | ||
// @flow | ||
import React, {useState} from 'react'; | ||
import {observer} from 'mobx-react-lite'; | ||
import {compose, get, filter, lowerCase, contains} from 'lodash/fp'; | ||
import {InputBase, IconButton} from '@material-ui/core'; | ||
import {Search as SearchIcon} from '@material-ui/icons'; | ||
import NodesStore from 'v2/stores/nodes'; | ||
|
||
import SearchResult from './result'; | ||
import useStyles from './styles'; | ||
|
||
type SearchProps = { | ||
onSubmit: (val: string) => void, | ||
}; | ||
|
||
const Search = ({onSubmit}: SearchProps) => { | ||
const Search = () => { | ||
const classes = useStyles(); | ||
const {validators} = NodesStore; | ||
const [value, setValue] = useState(''); | ||
const [isDirty, setDirty] = useState(false); | ||
const [isFocus, setFocus] = useState(false); | ||
const [searchResult, setSearchResult] = useState([]); | ||
|
||
const onFocus = () => setFocus(true); | ||
const onBlur = () => { | ||
setTimeout(() => { | ||
setFocus(false); | ||
}, 250); | ||
}; | ||
|
||
const handleClear = () => { | ||
setDirty(false); | ||
setValue(''); | ||
setSearchResult([]); | ||
}; | ||
|
||
const handleSearch = ({currentTarget}: SyntheticEvent<HTMLInputElement>) => { | ||
if (!currentTarget.value) { | ||
handleClear(); | ||
return; | ||
} | ||
setValue(currentTarget.value); | ||
const filteredValidators = filter(v => { | ||
const lowerVal = lowerCase(value); | ||
return ( | ||
compose(contains(lowerVal), lowerCase, get('nodePubkey'))(v) || | ||
compose(contains(lowerVal), lowerCase, get('identity.keybaseUsername'))(v) | ||
); | ||
})(validators); | ||
setDirty(true); | ||
setSearchResult(filteredValidators); | ||
}; | ||
const handleSubmit = () => { | ||
onSubmit(value); | ||
}; | ||
|
||
return ( | ||
<form className={classes.root} onSubmit={handleSubmit}> | ||
<InputBase | ||
className={classes.input} | ||
placeholder="Search by transaction hash / block number / application ID" | ||
classes={{ | ||
root: classes.inputRoot, | ||
input: classes.inputInput, | ||
}} | ||
value={value} | ||
onChange={handleSearch} | ||
<div className={classes.root}> | ||
<div className={classes.form}> | ||
<InputBase | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
className={classes.input} | ||
placeholder="Search by validators address / keybase" | ||
classes={{ | ||
root: classes.inputRoot, | ||
input: classes.inputInput, | ||
}} | ||
value={value} | ||
onChange={handleSearch} | ||
/> | ||
<IconButton size="small" className={classes.btn}> | ||
<SearchIcon /> | ||
</IconButton> | ||
</div> | ||
<SearchResult | ||
isDirty={isDirty} | ||
isFocus={isFocus} | ||
onClear={handleClear} | ||
items={searchResult} | ||
/> | ||
<IconButton size="small" className={classes.btn}> | ||
<SearchIcon /> | ||
</IconButton> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Search; | ||
export default observer(Search); |
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,41 @@ | ||
// @flow | ||
import React, {memo} from 'react'; | ||
import {map} from 'lodash/fp'; | ||
import {Link} from 'react-router-dom'; | ||
import type {Validator} from 'v2/@types/validator'; | ||
|
||
import useStyles from './styles'; | ||
|
||
type SearchResultProps = { | ||
items: Validator[], | ||
onClear: () => void, | ||
isDirty: boolean, | ||
isFocus: boolean, | ||
}; | ||
|
||
const SearchResult = ({isDirty, isFocus, items, onClear}: SearchResultProps) => { | ||
const classes = useStyles(); | ||
const renderItem = ({nodePubkey}: {nodePubkey: string}) => ( | ||
<li className={classes.item} key={nodePubkey}> | ||
<Link onClick={onClear} to={`/rc/validators/${nodePubkey}`}> | ||
{nodePubkey} | ||
</Link> | ||
</li> | ||
); | ||
if ((!isDirty && !items.length ) || !isFocus) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={classes.list}> | ||
<div className={classes.title}> | ||
{!items.length | ||
? 'There were no results for this search term.' | ||
: 'Validators'} | ||
</div> | ||
<ul>{map(renderItem)(items)}</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default memo(SearchResult); |
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.