1
0

Content.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. code={current.content || ''}
  61. setValue={this.setValue.bind(this)}
  62. show_search={show_search}
  63. />
  64. {show_search ? (
  65. <div className={styles['search-bar-wrapper']}>
  66. <SearchBar lang={lang}/>
  67. </div>
  68. ) : null}
  69. </div>
  70. )
  71. }
  72. }