WorkspaceContent.jsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import Folder from '../component/Workspace/Folder.jsx'
  4. import FileItem from '../component/Workspace/FileItem.jsx'
  5. import FileItemHeader from '../component/Workspace/FileItemHeader.jsx'
  6. import PageWrapper from '../component/common/layout/PageWrapper.jsx'
  7. import PageTitle from '../component/common/layout/PageTitle.jsx'
  8. import PageContent from '../component/common/layout/PageContent.jsx'
  9. import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
  10. import pluginDatabase from '../plugin/index.js'
  11. import {
  12. getPluginList,
  13. getWorkspaceContent
  14. } from '../action-creator.async.js'
  15. import { setActiveFileContent } from '../action-creator.sync.js'
  16. class WorkspaceContent extends React.Component {
  17. constructor (props) {
  18. super(props)
  19. this.state = {
  20. activeFileType: ''
  21. }
  22. }
  23. componentDidMount () {
  24. this.props.dispatch(getWorkspaceContent(/* this.props.workspace.id */1))
  25. this.props.dispatch(getPluginList())
  26. }
  27. handleClickFileItem = file => {
  28. this.props.dispatch(setActiveFileContent(file))
  29. }
  30. render () {
  31. const { workspace, activeFileContent, plugin } = this.props
  32. const PluginContainer = (pluginDatabase.find(p => p.name === activeFileContent.type) || {container: '<div>unknow</div>'}).container
  33. return (
  34. <PageWrapper customeClass='workspace'>
  35. <PageTitle
  36. parentClass='workspace__header'
  37. customClass='justify-content-between'
  38. title={workspace.title}
  39. >
  40. <DropdownCreateButton parentClass='workspace__header__btnaddworkspace' />
  41. </PageTitle>
  42. <PageContent parentClass='workspace__content'>
  43. <div className='workspace__content__fileandfolder folder__content active'>
  44. <FileItemHeader />
  45. { workspace.content.map(c => c.type === 'folder'
  46. ? <Folder plugin={plugin} folderData={c} key={c.id} />
  47. : (
  48. <FileItem
  49. name={c.title}
  50. type={c.type}
  51. icon={(plugin[c.type] || {icon: ''}).icon}
  52. status={c.status}
  53. onClickItem={() => this.handleClickFileItem(c)}
  54. key={c.id}
  55. />
  56. )
  57. )}
  58. </div>
  59. <DropdownCreateButton customClass='workspace__content__button mb-5' />
  60. <div id='pluginContainer'>
  61. { activeFileContent.display && <PluginContainer /> }
  62. </div>
  63. </PageContent>
  64. </PageWrapper>
  65. )
  66. }
  67. }
  68. const mapStateToProps = ({ workspace, activeFileContent, plugin }) => ({ workspace, activeFileContent, plugin })
  69. export default connect(mapStateToProps)(WorkspaceContent)