Folder.jsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 }, 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 folderData={c} key={c.id} isLast={i === content.length - 1} />
  54. : <FileItem
  55. icon={(app[c.type] || {icon: ''}).icon}
  56. name={c.title}
  57. type={c.type}
  58. status={c.status}
  59. onClickItem={() => {}}
  60. isLast={i === content.length - 1}
  61. key={c.id}
  62. />
  63. )}
  64. </div>
  65. </div>
  66. )
  67. }
  68. }
  69. export default translate()(Folder)
  70. Folder.propTypes = {
  71. folderData: PropTypes.shape({
  72. title: PropTypes.string.isRequired,
  73. content: PropTypes.array
  74. }),
  75. app: PropTypes.object
  76. }