Folder.jsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react'
  2. import { translate } from 'react-i18next'
  3. import PropTypes from 'prop-types'
  4. import classnames from 'classnames'
  5. import FileItem from './FileItem.jsx'
  6. // @TODO set Folder as a component, state open will come from parent container (which will come from redux) // update: or not ?
  7. class Folder extends React.Component {
  8. constructor (props) {
  9. super(props)
  10. this.state = {
  11. open: false
  12. }
  13. }
  14. handleClickToggleFolder = () => this.setState({open: !this.state.open})
  15. handleClickNewFile = e => {
  16. e.stopPropagation() // because we have a link inside a link (togler and newFile)
  17. console.log('new file') // @TODO
  18. }
  19. render () {
  20. const { app, folderData: { title, content }, onClickItem, isLast, t } = this.props
  21. return (
  22. <div className={classnames('folder', {'active': this.state.open, 'item-last': isLast})}>
  23. <div className='folder__header' onClick={this.handleClickToggleFolder}>
  24. <div className='folder__header__triangleborder'>
  25. <div className='folder__header__triangleborder__triangle' />
  26. </div>
  27. <div className='folder__header__name'>
  28. <div className='folder__header__name__icon'>
  29. <i className='fa fa-folder-open-o' />
  30. </div>
  31. <div className='folder__header__name__text'>
  32. { title }
  33. </div>
  34. <div className='folder__header__name__addbtn' onClick={this.handleClickNewFile}>
  35. <div className='folder__header__name__addbtn__text btn btn-primary'>
  36. {t('Folder.create')} ...
  37. </div>
  38. </div>
  39. </div>
  40. <div className='folder__header__contenttype'>
  41. <div className='folder__header__contenttype__text'>
  42. {t('Folder.content_type')} :
  43. </div>
  44. <div className='folder__header__contenttype__icon'>
  45. <i className='fa fa-list-ul' />
  46. <i className='fa fa-file-text-o' />
  47. <i className='fa fa-comments' />
  48. </div>
  49. </div>
  50. </div>
  51. <div className='folder__content'>
  52. { content.map((c, i) => c.type === 'folder'
  53. ? <Folder
  54. folderData={c}
  55. onClickItem={onClickItem}
  56. isLast={isLast}
  57. key={c.id}
  58. />
  59. : <FileItem
  60. icon={(app[c.type] || {icon: ''}).icon}
  61. name={c.title}
  62. type={c.type}
  63. status={c.status}
  64. onClickItem={() => onClickItem(c)}
  65. isLast={isLast && i === content.length - 1}
  66. key={c.id}
  67. />
  68. )}
  69. </div>
  70. </div>
  71. )
  72. }
  73. }
  74. export default translate()(Folder)
  75. Folder.propTypes = {
  76. folderData: PropTypes.shape({
  77. title: PropTypes.string.isRequired,
  78. content: PropTypes.array
  79. }),
  80. app: PropTypes.object
  81. }