import React, { PropTypes, Component } from 'react'; import { intlShape } from 'react-intl'; import Formsy from 'formsy-react'; import FRC from 'formsy-react-components'; import { withRouter } from 'react-router' const Input = FRC.Input; // see: http://stackoverflow.com/questions/1909441/jquery-keyup-delay const delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); class SearchForm extends Component{ constructor(props) { super(props); this.search = this.search.bind(this); this.state = { search: props.router.location.query.query || '' } } componentWillReceiveProps(nextProps) { this.setState({ search: this.props.router.location.query.query || '' }); } search(data) { const router = this.props.router; const query = data.searchQuery === '' ? {} : {query: data.searchQuery}; // if (router.location.pathName !== "/") { // router.push({pathName: "/"}); // } delay(() => { router.push({pathName: "/", query: query}); }, 700 ); } render() { return (