SearchBox.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This is the root component for #search-top
  2. import React from 'react';
  3. import SearchForm from './SearchForm';
  4. import SearchSuggest from './SearchSuggest';
  5. import axios from 'axios'
  6. export default class SearchBox extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. searchingKeyword: '',
  11. searchedPages: [],
  12. searchError: null,
  13. }
  14. this.search = this.search.bind(this);
  15. }
  16. search(data) {
  17. const keyword = data.keyword;
  18. axios.get('/_api/search', {params: {q: keyword}})
  19. .then((res) => {
  20. if (res.data.ok) {
  21. this.setState({
  22. searchedPages: res.data.data
  23. });
  24. }
  25. // TODO error
  26. })
  27. .catch((res) => {
  28. // TODO error
  29. });
  30. }
  31. render() {
  32. return (
  33. <div className="search-box">
  34. <SearchForm onSearchFormChanged={this.search} />
  35. <SearchSuggest searchedPages={this.state.searchedPages} />
  36. </div>
  37. );
  38. }
  39. }
  40. SearchBox.propTypes = {
  41. //pollInterval: React.PropTypes.number,
  42. };
  43. SearchBox.defaultProps = {
  44. //pollInterval: 1000,
  45. };