NewPageNameInputter.js 1.9 KB

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