Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

scan: search bar on validator home page #1906

Merged
merged 14 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- (feat) [\#1938](https://github.com/bandprotocol/bandchain/pull/1938) Add validator's image from identity
- (impv) [\#1928](https://github.com/bandprotocol/bandchain/pull/1928) Add chainID for guanyu-devnet
- (impv) [\#1925](https://github.com/bandprotocol/bandchain/pull/1925) Removed input field for unused oracle script input
- (impv) [\#1906](https://github.com/bandprotocol/bandchain/pull/1906/files) Add searchbar on validator home page

### Bridges

Expand Down
52 changes: 41 additions & 11 deletions scan/src/pages/ValidatorHomePage.re
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ module Styles = {
marginLeft(`pxFloat(1.6)),
transform(`rotate(`deg(down ? 0. : 180.))),
]);
let searchContainer = style([display(`flex), justifyContent(`flexEnd), alignItems(`center)]);
let searchBar =
style([
display(`flex),
width(`percent(30.)),
height(`px(30)),
paddingLeft(`px(9)),
borderRadius(`px(4)),
border(`px(1), `solid, Colors.blueGray3),
]);
};

module ToggleButton = {
Expand Down Expand Up @@ -133,7 +143,12 @@ let renderBody =
<Col size=0.9>
{switch (validatorSub) {
| Data({operatorAddress, moniker, identity}) =>
<ValidatorMonikerLink validatorAddress=operatorAddress moniker identity width={`px(180)} />
<ValidatorMonikerLink
validatorAddress=operatorAddress
moniker
identity
width={`px(180)}
/>
| _ => <LoadingCensorBar width=150 height=15 />
}}
</Col>
Expand Down Expand Up @@ -354,7 +369,7 @@ module SortableTHead = {

module ValidatorList = {
[@react.component]
let make = (~allSub) => {
let make = (~allSub, ~searchTerm) => {
let (sortedBy, setSortedBy) = React.useState(_ => VotingPowerDesc);

let toggle = (sortedByAsc, sortedByDesc) =>
Expand Down Expand Up @@ -430,9 +445,15 @@ module ValidatorList = {
votesBlock,
)) =>
let validators = addUptimeOnValidators(rawValidators, votesBlock);
let filteredValidator =
searchTerm |> Js.String.length == 0
? validators
: validators->Belt_Array.keep(validator => {
Js.String.includes(searchTerm, validator.moniker |> Js.String.toLowerCase)
});
<>
{validators->Belt_Array.size > 0
? validators
{filteredValidator->Belt_Array.size > 0
? filteredValidator
->sorting(sortedBy)
->Belt_Array.map(e =>
renderBody(e.rank, Sub.resolve(e), bondedTokenCount.amount)
Expand Down Expand Up @@ -470,6 +491,7 @@ let getCurrentDay = _ => {
let make = () => {
let (prevDayTime, setPrevDayTime) = React.useState(getPrevDay);
let (currentTime, setCurrentTime) = React.useState(getCurrentDay);
let (searchTerm, setSearchTerm) = React.useState(_ => "");

React.useEffect0(() => {
let timeOutID =
Expand Down Expand Up @@ -525,12 +547,6 @@ let make = () => {
| _ => React.null
}}
</div>
<Col>
{switch (topPartAllSub) {
| Data(_) => <ToggleButton isActive setIsActive />
| _ => React.null
}}
</Col>
</Row>
<div className=Styles.highlight>
<Row>
Expand Down Expand Up @@ -596,7 +612,21 @@ let make = () => {
</Col>
</Row>
</div>
<ValidatorList allSub />
<div className=Styles.searchContainer>
<input
type_="text"
className=Styles.searchBar
placeholder="Search Validator"
onChange={event => {
let newVal = ReactEvent.Form.target(event)##value;
setSearchTerm(_ => newVal);
}}
/>
<HSpacing size=Spacing.sm />
<Col> <ToggleButton isActive setIsActive /> </Col>
</div>
<VSpacing size=Spacing.md />
<ValidatorList allSub searchTerm />
<VSpacing size=Spacing.lg />
</>;
};