Content.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. import React from 'react'
  7. import { Icon } from 'antd'
  8. import classnames from 'classnames'
  9. import SearchBar from './SearchBar'
  10. import Agent from '../Agent'
  11. import Editor from './Editor'
  12. import styles from './Content.less'
  13. export default class Content extends React.Component {
  14. constructor (props) {
  15. super(props)
  16. this.state = {
  17. is_loading: this.props.current.is_loading,
  18. show_search: false
  19. }
  20. }
  21. setValue (v) {
  22. this.props.setHostsContent(v)
  23. }
  24. componentDidMount () {
  25. Agent.on('search:start', () => {
  26. this.setState({show_search: true})
  27. })
  28. Agent.on('search:end', () => {
  29. this.setState({show_search: false})
  30. })
  31. }
  32. render () {
  33. let {current, readonly, lang} = this.props
  34. let {show_search} = this.state
  35. return (
  36. <div id="sh-content" className={styles.root}>
  37. <div className={styles.inform}>
  38. <span
  39. className={classnames({
  40. [styles.loading]: 1,
  41. [styles.show]: this.state.is_loading
  42. })}
  43. >loading...</span>
  44. <Icon
  45. type="lock"
  46. className={classnames({
  47. [styles.show]: readonly,
  48. iconfont: 1,
  49. 'icon-lock2': 1
  50. })}
  51. title={lang.readonly}
  52. />
  53. </div>
  54. <div className={classnames({
  55. [styles.errorMessage]: 1,
  56. [styles.show]: !!current.error
  57. })}>{current.error}</div>
  58. <Editor
  59. readonly={readonly}
  60. id={current.id}
  61. code={current.content || ''}
  62. setValue={this.setValue.bind(this)}
  63. show_search={show_search}
  64. />
  65. {show_search ? (
  66. <div className={styles['search-bar-wrapper']}>
  67. <SearchBar lang={lang}/>
  68. </div>
  69. ) : null}
  70. </div>
  71. )
  72. }
  73. }