WorkspaceContent.jsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import appFactory from '../appFactory.js'
  4. import Folder from '../component/Workspace/Folder.jsx'
  5. import FileItem from '../component/Workspace/FileItem.jsx'
  6. import FileItemHeader from '../component/Workspace/FileItemHeader.jsx'
  7. import PageWrapper from '../component/common/layout/PageWrapper.jsx'
  8. import PageTitle from '../component/common/layout/PageTitle.jsx'
  9. import PageContent from '../component/common/layout/PageContent.jsx'
  10. import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
  11. import {
  12. getAppList,
  13. getWorkspaceContent
  14. } from '../action-creator.async.js'
  15. class WorkspaceContent extends React.Component {
  16. constructor (props) {
  17. super(props)
  18. this.state = {
  19. activeFileType: ''
  20. }
  21. }
  22. componentDidMount () {
  23. const { workspaceList, app, match, dispatch } = this.props
  24. if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws))
  25. else if (workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id)) // load first ws if none specified
  26. Object.keys(app).length === 0 && dispatch(getAppList())
  27. }
  28. componentDidUpdate (prevProps) {
  29. const { workspace, workspaceList, match, dispatch } = this.props
  30. // if a workspace is already loaded and the idws in url hasn't changed, do nothing
  31. if (workspace.id !== -1 && prevProps.match.params.idws === match.params.idws) return
  32. // if the idws in url has changed, load the new workspace
  33. if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws))
  34. // else bellow is for loading url PAGE_NAME.HOME (without an idws), when workspaceList is loaded, load the first workspace
  35. else if (match.params.idws === undefined && workspace.id === -1 && workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id))
  36. }
  37. handleClickContentItem = content => {
  38. this.props.renderApp(this.props.user, this.props.workspace, this.props.app, content)
  39. // Côme - 2018/03/08 - line bellow is useless because we cannot call the reducer again when hiding app since the call comes from the app
  40. // dispatch(setActiveFileContentActive(content))
  41. }
  42. render () {
  43. const { workspace, app } = this.props
  44. return (
  45. <PageWrapper customeClass='workspace'>
  46. <PageTitle
  47. parentClass='workspace__header'
  48. customClass='justify-content-between'
  49. title={workspace.title}
  50. >
  51. <DropdownCreateButton parentClass='workspace__header__btnaddworkspace' />
  52. </PageTitle>
  53. <PageContent parentClass='workspace__content'>
  54. <div className='workspace__content__fileandfolder folder__content active'>
  55. <FileItemHeader />
  56. { workspace.content.map((c, i) => c.type === 'folder'
  57. ? <Folder app={app} folderData={c} key={c.id} isLast={i === workspace.content.length - 1} />
  58. : (
  59. <FileItem
  60. name={c.title}
  61. type={c.type}
  62. icon={(app[c.type] || {icon: ''}).icon}
  63. status={c.status}
  64. onClickItem={() => this.handleClickContentItem(c)}
  65. isLast={i === workspace.content.length - 1}
  66. key={c.id}
  67. />
  68. )
  69. )}
  70. </div>
  71. <DropdownCreateButton customClass='workspace__content__button mb-5' />
  72. <div id='appContainer' />
  73. </PageContent>
  74. </PageWrapper>
  75. )
  76. }
  77. }
  78. const mapStateToProps = ({ user, workspace, workspaceList, app }) => ({ user, workspace, workspaceList, app })
  79. export default connect(mapStateToProps)(appFactory(WorkspaceContent))