/*
* Alice (Prefix-)Lookup
*/
import {debounce} from 'underscore'
import React from 'react'
import {connect} from 'react-redux'
import {replace} from 'react-router-redux'
import {setLookupQueryValue} from './actions'
import Content from 'components/content'
import LookupResults from './results'
import SearchInput from 'components/search-input'
import QuickLinks from 'components/routeservers/routes/quick-links'
class LookupHelp extends React.Component {
render() {
if(this.props.query != '') {
return null;
}
return (
Did you know?
You can search for
- Prefixes,
- Peers by entering their name and
- ASNs by prefixing them with 'AS'
Just start typing!
);
}
}
class Lookup extends React.Component {
constructor(props) {
super(props);
this.debouncedDispatch = debounce(this.props.dispatch, 400);
}
doLookup(q) {
// Make path
const destination = {
pathname: "/search",
search: `?q=${q}`
};
// Set lookup params
this.props.dispatch(setLookupQueryValue(q));
this.debouncedDispatch(replace(destination));
}
componentDidMount() {
// this is yucky but the debounced
// search input seems to kill the ref=
let input = document.getElementById('lookup-search-input');
input.focus();
let value = input.value;
input.value = "";
input.value = value;
}
render() {
return (
Search on all route servers
this.doLookup(e.target.value)} />
)
}
}
export default connect(
(state) => {
const lookup = state.lookup;
return {
query: state.lookup.query,
queryValue: state.lookup.queryValue,
isLoading: state.lookup.isLoading,
error: state.lookup.error,
routes: {
filtered: {
loading: lookup.isLoading,
totalResults: lookup.totalRoutesFiltered,
},
received: {
loading: lookup.isLoading,
totalResults: lookup.totalRoutesImported,
},
notExported: {
loading: false,
totalResults: 0,
}
}
}
}
)(Lookup);