WorkspaceContent.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 {
  11. getPluginList,
  12. getWorkspaceContent
  13. } from '../action-creator.async.js'
  14. import { setActiveFileContent, hideActiveFileContent } from '../action-creator.sync.js'
  15. import PopinFixed from '../component/common/PopinFixed/PopinFixed.jsx'
  16. import PopinFixedHeader from '../component/common/PopinFixed/PopinFixedHeader.jsx'
  17. import PopinFixedOption from '../component/common/PopinFixed/PopinFixedOption.jsx'
  18. import PopinFixedContent from '../component/common/PopinFixed/PopinFixedContent.jsx'
  19. import PluginContentType from '../component/PluginContentType.jsx'
  20. class WorkspaceContent extends React.Component {
  21. constructor (props) {
  22. super(props)
  23. this.state = {
  24. activeFileType: ''
  25. }
  26. }
  27. componentDidMount () {
  28. this.props.dispatch(getWorkspaceContent(/* this.props.workspace.id */1))
  29. this.props.dispatch(getPluginList())
  30. }
  31. handleClickFileItem = file => {
  32. console.log(file)
  33. this.props.dispatch(setActiveFileContent(file))
  34. }
  35. handleClickCloseBtn = () => {
  36. this.props.dispatch(hideActiveFileContent())
  37. }
  38. render () {
  39. const { workspace, activeFileContent, plugin } = this.props
  40. const pluginContent = (() => {
  41. switch (activeFileContent.type) {
  42. case 'PageHtml':
  43. return <PopinFixed customClass={`${plugin.pageHtml.customClass}`}>
  44. <PopinFixedHeader
  45. customClass={`${plugin.pageHtml.customClass}`}
  46. icon={plugin.pageHtml.icon}
  47. name={activeFileContent.title}
  48. onClickCloseBtn={this.handleClickCloseBtn}
  49. />
  50. <PopinFixedOption customClass={`${plugin.pageHtml.customClass}`} />
  51. <PopinFixedContent customClass={`${plugin.pageHtml.customClass}__contentpage`}>
  52. <PluginContentType
  53. file={activeFileContent}
  54. customClass={`${plugin.pageHtml.customClass}`}
  55. />
  56. </PopinFixedContent>
  57. </PopinFixed>
  58. }
  59. })()
  60. return (
  61. <PageWrapper customeClass='workspace'>
  62. <PageTitle
  63. parentClass='workspace__header'
  64. customClass='justify-content-between'
  65. title={workspace.title}
  66. >
  67. <DropdownCreateButton parentClass='workspace__header__btnaddworkspace' />
  68. </PageTitle>
  69. <PageContent parentClass='workspace__content'>
  70. <div className='workspace__content__fileandfolder folder__content active'>
  71. <FileItemHeader />
  72. { workspace.content.map(c => c.type === 'folder'
  73. ? <Folder folderData={c} key={c.id} />
  74. : (
  75. <FileItem
  76. name={c.title}
  77. type={c.type}
  78. status={c.status}
  79. onClickItem={() => this.handleClickFileItem(c)}
  80. key={c.id}
  81. />
  82. )
  83. )}
  84. </div>
  85. <DropdownCreateButton customClass='workspace__content__button mb-5' />
  86. <div id='pluginContainer'>
  87. { activeFileContent.display && pluginContent }
  88. </div>
  89. </PageContent>
  90. </PageWrapper>
  91. )
  92. }
  93. }
  94. const mapStateToProps = ({ workspace, activeFileContent, plugin }) => ({ workspace, activeFileContent, plugin })
  95. export default connect(mapStateToProps)(WorkspaceContent)