2016-03-22 11:04:59 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-09 17:42:20 +09:00
|
|
|
import { intlShape } from 'react-intl';
|
2016-03-23 11:46:56 +09:00
|
|
|
import Router from '../router.js'
|
2016-03-22 11:04:59 +09:00
|
|
|
import Formsy from 'formsy-react';
|
|
|
|
import FRC from 'formsy-react-components';
|
|
|
|
|
|
|
|
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() {
|
|
|
|
super();
|
|
|
|
this.search = this.search.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
search(data) {
|
|
|
|
|
2016-03-23 11:46:56 +09:00
|
|
|
if (Router.getRouteName() !== "posts.list") {
|
2016-06-11 16:37:03 +09:00
|
|
|
// Router.go("posts.list");
|
2016-03-22 11:04:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.searchQuery === '') {
|
|
|
|
data.searchQuery = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(function(){
|
2016-06-11 16:37:03 +09:00
|
|
|
// Router.setQueryParams({query: data.searchQuery});
|
2016-03-22 11:04:59 +09:00
|
|
|
}, 700 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
2016-06-11 16:37:03 +09:00
|
|
|
const currentQuery = "foo";
|
2016-05-03 12:44:50 +09:00
|
|
|
|
2016-03-22 11:04:59 +09:00
|
|
|
return (
|
|
|
|
<div className="search-form">
|
|
|
|
<Formsy.Form onChange={this.search}>
|
|
|
|
<Input
|
|
|
|
name="searchQuery"
|
2016-05-03 12:44:50 +09:00
|
|
|
value={currentQuery}
|
2016-06-09 17:42:20 +09:00
|
|
|
placeholder={this.context.intl.formatMessage({id: "posts.search"})}
|
2016-03-22 11:04:59 +09:00
|
|
|
type="text"
|
2016-03-30 10:06:12 +09:00
|
|
|
layout="elementOnly"
|
2016-03-22 11:04:59 +09:00
|
|
|
/>
|
|
|
|
</Formsy.Form>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 12:44:50 +09:00
|
|
|
SearchForm.contextTypes = {
|
|
|
|
currentRoute: React.PropTypes.object,
|
2016-06-09 17:42:20 +09:00
|
|
|
currentUser: React.PropTypes.object,
|
|
|
|
intl: intlShape
|
2016-05-03 12:44:50 +09:00
|
|
|
}
|
|
|
|
|
2016-03-22 11:04:59 +09:00
|
|
|
module.exports = SearchForm;
|
|
|
|
export default SearchForm;
|