Folder.jsx 2.9KB

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