OpenContentApp.jsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { withRouter } from 'react-router'
  4. import appFactory from '../appFactory.js'
  5. export class OpenContentApp extends React.Component {
  6. openContentApp = () => {
  7. const { idWorkspace, appOpened, user, workspaceContent, contentType, renderApp, match } = this.props
  8. if (isNaN(idWorkspace)) return
  9. if (['type', 'idcts'].every(p => p in match.params) && match.params.type !== 'contents' && workspaceContent.id !== -1 && workspaceContent.length) {
  10. // @TODO test validity of params, idcts isNaN and type includes list of available content type
  11. const contentToOpen = {
  12. content_id: parseInt(match.params.idcts),
  13. workspace_id: parseInt(idWorkspace),
  14. type: match.params.type
  15. }
  16. console.log('contentToOpen', contentToOpen)
  17. if (!appOpened) {
  18. renderApp(
  19. contentType.find(ct => ct.slug === contentToOpen.type),
  20. user,
  21. contentToOpen
  22. )
  23. this.props.updateAppOpened(true)
  24. } else {
  25. GLOBAL_dispatchEvent({
  26. type: 'html-documents_reloadContent',
  27. data: contentToOpen
  28. })
  29. }
  30. }
  31. }
  32. componentDidMount () {
  33. console.log('OpenContentApp did Mount', this.props)
  34. this.openContentApp()
  35. }
  36. componentDidUpdate () {
  37. console.log('OpenContentApp did Update', this.props)
  38. this.openContentApp()
  39. }
  40. render () {
  41. return null
  42. }
  43. }
  44. const mapStateToProps = ({ user, workspaceContent, contentType }) => ({ user, workspaceContent, contentType })
  45. export default withRouter(connect(mapStateToProps)(appFactory(OpenContentApp)))