NewPageNameInputter.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import { FormGroup, Button, InputGroup } from 'react-bootstrap';
  3. import { AsyncTypeahead } from 'react-bootstrap-typeahead';
  4. import UserPicture from './User/UserPicture';
  5. import PageListMeta from './PageList/PageListMeta';
  6. import PagePath from './PageList/PagePath';
  7. import PropTypes from 'prop-types';
  8. import SearchTypeahead from './SearchTypeahead';
  9. export default class NewPageNameInputter extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. input: '',
  14. keyword: '',
  15. isLoading: false,
  16. searchError: null,
  17. };
  18. this.crowi = this.props.crowi;
  19. this.onSearchSuccess = this.onSearchSuccess.bind(this);
  20. this.onSearchError = this.onSearchError.bind(this);
  21. this.getParentPageName = this.getParentPageName.bind(this);
  22. }
  23. componentDidMount() {
  24. }
  25. componentWillUnmount() {
  26. }
  27. onSearchSuccess(res) {
  28. this.setState({
  29. isLoading: false,
  30. keyword: '',
  31. pages: res.data,
  32. });
  33. }
  34. onSearchError(err) {
  35. this.setState({
  36. isLoading: false,
  37. searchError: err,
  38. });
  39. }
  40. getParentPageName(path) {
  41. if (path == '/') {
  42. return path;
  43. }
  44. if (path.match(/.+\/$/)) {
  45. return path;
  46. }
  47. return path + '/';
  48. }
  49. render() {
  50. const emptyLabel = (this.state.searchError !== null)
  51. ? 'Error on searching.'
  52. : 'No matches found on title...';
  53. return (
  54. <SearchTypeahead
  55. crowi={this.crowi}
  56. onSearchSuccess={this.onSearchSuccess}
  57. onSearchError={this.onSearchError}
  58. emptyLabel={emptyLabel}
  59. keywordOnInit={this.getParentPageName(this.props.parentPageName)}
  60. />
  61. );
  62. }
  63. }
  64. NewPageNameInputter.propTypes = {
  65. crowi: PropTypes.object.isRequired,
  66. parentPageName: PropTypes.string.isRequired,
  67. };
  68. NewPageNameInputter.defaultProps = {
  69. };