Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
fix: review comments and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-calavera authored and sunnygleason committed Jul 26, 2019
1 parent aab4795 commit dcda50a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default makeStyles(theme => ({
color: getColor('main')(theme),
marginTop: 40,
letterSpacing: 3.4,
}
},
},
changes: {
fontSize: 18,
Expand Down
33 changes: 24 additions & 9 deletions src/v2/components/Search/index.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// @flow
import React, {useState} from 'react';
import {observer} from 'mobx-react-lite';
import {compose, get, filter, lowerCase, contains} from 'lodash/fp';
import {compose, get, filter, toLower, 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 {MIN_TERM_LEN} from '../../constants';

import SearchResult from './result';
import useStyles from './styles';

const Search = () => {
const classes = useStyles();
const {validators} = NodesStore;
const [value, setValue] = useState('');
const [query, setQuery] = useState('');
const [isDirty, setDirty] = useState(false);
const [isFocus, setFocus] = useState(false);
const [searchResult, setSearchResult] = useState([]);
Expand All @@ -26,21 +27,35 @@ const Search = () => {

const handleClear = () => {
setDirty(false);
setValue('');
setQuery('');
setSearchResult([]);
};

const handleSearch = ({currentTarget}: SyntheticEvent<HTMLInputElement>) => {
if (!currentTarget.value) {
const {value} = currentTarget;
if (!value) {
handleClear();
return;
}
setValue(currentTarget.value);
setQuery(value);
if (value.length < MIN_TERM_LEN) {
setDirty(false);
setSearchResult([]);
return;
}
const filteredValidators = filter(v => {
const lowerVal = lowerCase(value);
const lowerVal = toLower(value);
return (
compose(contains(lowerVal), lowerCase, get('nodePubkey'))(v) ||
compose(contains(lowerVal), lowerCase, get('identity.keybaseUsername'))(v)
compose(
contains(lowerVal),
toLower,
get('nodePubkey'),
)(v) ||
compose(
contains(lowerVal),
toLower,
get('identity.keybaseUsername'),
)(v)
);
})(validators);
setDirty(true);
Expand All @@ -59,7 +74,7 @@ const Search = () => {
root: classes.inputRoot,
input: classes.inputInput,
}}
value={value}
value={query}
onChange={handleSearch}
/>
<IconButton size="small" className={classes.btn}>
Expand Down
9 changes: 7 additions & 2 deletions src/v2/components/Search/result.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ type SearchResultProps = {
isFocus: boolean,
};

const SearchResult = ({isDirty, isFocus, items, onClear}: SearchResultProps) => {
const SearchResult = ({
isDirty,
isFocus,
items,
onClear,
}: SearchResultProps) => {
const classes = useStyles();
const renderItem = ({nodePubkey}: {nodePubkey: string}) => (
<li className={classes.item} key={nodePubkey}>
Expand All @@ -22,7 +27,7 @@ const SearchResult = ({isDirty, isFocus, items, onClear}: SearchResultProps) =>
</Link>
</li>
);
if ((!isDirty && !items.length ) || !isFocus) {
if ((!isDirty && !items.length) || !isFocus) {
return null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/v2/components/Search/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export default makeStyles(theme => {
padding: '5px 0',
display: 'block',
'&:hover': {
color: getColor('dark')(theme)
}
}
color: getColor('dark')(theme),
},
},
},
},
title: {
color: getColor('dark')(theme)
}
color: getColor('dark')(theme),
},
};
});
12 changes: 10 additions & 2 deletions src/v2/components/Validators/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
hint: '',
value() {
return identity.website ? (
<a href={identity.website}>{identity.website}</a>
<a target="_blank" rel="noopener noreferrer" href={identity.website}>
{identity.website}
</a>
) : (
''
);
Expand All @@ -116,7 +118,11 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
hint: '',
value() {
return identity.keybaseUsername ? (
<a href={`https://keybase.io/${identity.keybaseUsername}`}>
<a
target="_blank"
rel="noopener noreferrer"
href={`https://keybase.io/${identity.keybaseUsername}`}
>
{identity.keybaseUsername}
</a>
) : (
Expand Down Expand Up @@ -182,6 +188,8 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
fullWidth
color="primary"
href="https://github.com/solana-labs/tour-de-sol#validator-public-key-registration"
target="_blank"
rel="noopener noreferrer"
>
Connect To Keybase
</Button>
Expand Down
10 changes: 5 additions & 5 deletions src/v2/components/Validators/Detail/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ export default makeStyles(theme => ({
color: getColor('main')(theme),
textDecoration: 'none',
'&:hover': {
textDecoration: 'underline'
}
}
textDecoration: 'underline',
},
},
},
address: {
display: 'flex',
alignItem: 'center',
color: getColor('main')(theme)
}
color: getColor('main')(theme),
},
}));
1 change: 1 addition & 0 deletions src/v2/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MIN_TERM_LEN = 3;
5 changes: 2 additions & 3 deletions src/v2/stores/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class Store {

get validators() {
return map(vote => {
const cluster = find({pubkey: vote.nodePubkey})(
this.cluster.cluster,
) || {};
const cluster =
find({pubkey: vote.nodePubkey})(this.cluster.cluster) || {};
const {lng = 0, lat = 0, gossip} = cluster;
return {
...vote,
Expand Down

0 comments on commit dcda50a

Please sign in to comment.