12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import React from 'react'
- import { connect } from 'react-redux'
- import { withRouter } from 'react-router'
- import appFactory from '../../appFactory.js'
-
- export class OpenContentApp extends React.Component {
- openContentApp = () => {
- const { idWorkspace, appOpenedType, user, workspaceContent, contentType, renderApp, match } = this.props
-
- if (isNaN(idWorkspace) || idWorkspace === -1) return
-
- if (['type', 'idcts'].every(p => p in match.params) && match.params.type !== 'contents' && workspaceContent.length) {
- if (isNaN(match.params.idcts) || !contentType.map(c => c.slug).includes(match.params.type)) return
-
- const contentToOpen = {
- content_id: parseInt(match.params.idcts),
- workspace_id: parseInt(idWorkspace),
- type: match.params.type
- }
-
- console.log('%c<OpenContentApp> contentToOpen', 'color: #dcae84', contentToOpen)
-
- if (appOpenedType === contentToOpen.type) {
- GLOBAL_dispatchEvent({
- type: `${contentToOpen.type}_reloadContent`,
- data: contentToOpen
- })
- } else {
-
- if (appOpenedType !== false) GLOBAL_dispatchEvent({type: `${appOpenedType}_hideApp`})
-
- renderApp(
- contentType.find(ct => ct.slug === contentToOpen.type),
- user,
- contentToOpen
- )
- this.props.updateAppOpenedType(contentToOpen.type)
- }
- }
- }
-
- componentDidMount () {
- console.log('%c<OpenContentApp> did Mount', 'color: #dcae84', this.props)
-
- this.openContentApp()
- }
-
- componentDidUpdate () {
- console.log('%c<OpenContentApp> did Update', 'color: #dcae84', this.props)
-
- this.openContentApp()
- }
-
- render () {
- return null
- }
- }
-
- const mapStateToProps = ({ user, workspaceContent, contentType }) => ({ user, workspaceContent, contentType })
- export default withRouter(connect(mapStateToProps)(appFactory(OpenContentApp)))
|