|  | @@ -10,7 +10,6 @@ import PageWrapper from '../component/common/layout/PageWrapper.jsx'
 | 
	
		
			
			| 10 | 10 |  import PageTitle from '../component/common/layout/PageTitle.jsx'
 | 
	
		
			
			| 11 | 11 |  import PageContent from '../component/common/layout/PageContent.jsx'
 | 
	
		
			
			| 12 | 12 |  import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
 | 
	
		
			
			| 13 |  | -import PopupCreateContent from '../component/PopupCreateContent/PopupCreateContainer.jsx'
 | 
	
		
			
			| 14 | 13 |  import {
 | 
	
		
			
			| 15 | 14 |    getAppList,
 | 
	
		
			
			| 16 | 15 |    getWorkspaceContent,
 | 
	
	
		
			
			|  | @@ -18,7 +17,7 @@ import {
 | 
	
		
			
			| 18 | 17 |    getWorkspaceList
 | 
	
		
			
			| 19 | 18 |  } from '../action-creator.async.js'
 | 
	
		
			
			| 20 | 19 |  import {
 | 
	
		
			
			| 21 |  | -  newFlashMessage,
 | 
	
		
			
			|  | 20 | +  newFlashMessage, setAppList,
 | 
	
		
			
			| 22 | 21 |    setWorkspaceData,
 | 
	
		
			
			| 23 | 22 |    setWorkspaceListIsOpenInSidebar,
 | 
	
		
			
			| 24 | 23 |    updateWorkspaceListData
 | 
	
	
		
			
			|  | @@ -37,13 +36,29 @@ class WorkspaceContent extends React.Component {
 | 
	
		
			
			| 37 | 36 |        },
 | 
	
		
			
			| 38 | 37 |        workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null
 | 
	
		
			
			| 39 | 38 |      }
 | 
	
		
			
			|  | 39 | +
 | 
	
		
			
			|  | 40 | +    document.addEventListener('appCustomEvent', this.customEventReducer)
 | 
	
		
			
			|  | 41 | +  }
 | 
	
		
			
			|  | 42 | +
 | 
	
		
			
			|  | 43 | +  customEventReducer = ({ detail: { type, data } }) => {
 | 
	
		
			
			|  | 44 | +    switch (type) {
 | 
	
		
			
			|  | 45 | +      case 'openContentUrl':
 | 
	
		
			
			|  | 46 | +        this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.idContent))
 | 
	
		
			
			|  | 47 | +        break
 | 
	
		
			
			|  | 48 | +      case 'appClosed':
 | 
	
		
			
			|  | 49 | +        this.props.history.push(PAGE.WORKSPACE.CONTENT(this.props.workspace.id, ''))
 | 
	
		
			
			|  | 50 | +        break
 | 
	
		
			
			|  | 51 | +    }
 | 
	
		
			
			| 40 | 52 |    }
 | 
	
		
			
			| 41 | 53 |  
 | 
	
		
			
			| 42 | 54 |    async componentDidMount () {
 | 
	
		
			
			| 43 | 55 |      const { workspaceIdInUrl } = this.state
 | 
	
		
			
			| 44 | 56 |      const { user, workspaceList, app, match, location, dispatch } = this.props
 | 
	
		
			
			| 45 | 57 |  
 | 
	
		
			
			| 46 |  | -    if (Object.keys(app).length === 0) dispatch(getAppList()) // async but no need await
 | 
	
		
			
			|  | 58 | +    if (Object.keys(app).length === 0) {
 | 
	
		
			
			|  | 59 | +      const fetchGetAppList = await dispatch(getAppList())
 | 
	
		
			
			|  | 60 | +      if (fetchGetAppList.status === 200) dispatch(setAppList(fetchGetAppList.json))
 | 
	
		
			
			|  | 61 | +    }
 | 
	
		
			
			| 47 | 62 |  
 | 
	
		
			
			| 48 | 63 |      let wsToLoad = null
 | 
	
		
			
			| 49 | 64 |      if (match.params.idws !== undefined) wsToLoad = match.params.idws
 | 
	
	
		
			
			|  | @@ -64,34 +79,35 @@ class WorkspaceContent extends React.Component {
 | 
	
		
			
			| 64 | 79 |      if (wsToLoad === null) return // ws already loaded
 | 
	
		
			
			| 65 | 80 |  
 | 
	
		
			
			| 66 | 81 |      const wsContent = await dispatch(getWorkspaceContent(wsToLoad))
 | 
	
		
			
			| 67 |  | -    if (wsContent.status === 200) {
 | 
	
		
			
			| 68 |  | -      dispatch(setWorkspaceData(wsContent.json, qs.parse(location.search).type))
 | 
	
		
			
			| 69 |  | -
 | 
	
		
			
			| 70 |  | -      if (match.params.idcts) { // if a content id is in url, open it
 | 
	
		
			
			| 71 |  | -        const contentToOpen = wsContent.json.content.find(wsc => wsc.id === parseInt(match.params.idcts))
 | 
	
		
			
			| 72 |  | -        if (contentToOpen === undefined) return
 | 
	
		
			
			| 73 | 82 |  
 | 
	
		
			
			| 74 |  | -        this.handleClickContentItem(contentToOpen)
 | 
	
		
			
			| 75 |  | -      }
 | 
	
		
			
			| 76 |  | -    } else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
 | 
	
		
			
			|  | 83 | +    if (wsContent.status === 200) dispatch(setWorkspaceData(wsContent.json, qs.parse(location.search).type))
 | 
	
		
			
			|  | 84 | +    else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
 | 
	
		
			
			| 77 | 85 |    }
 | 
	
		
			
			| 78 | 86 |  
 | 
	
		
			
			| 79 | 87 |    componentDidUpdate (prevProps, prevState) {
 | 
	
		
			
			| 80 |  | -    const { user, match, dispatch } = this.props
 | 
	
		
			
			|  | 88 | +    const { app, workspace, user, renderApp, match, dispatch } = this.props
 | 
	
		
			
			| 81 | 89 |  
 | 
	
		
			
			| 82 | 90 |      if (this.state.workspaceIdInUrl === null) return
 | 
	
		
			
			| 83 | 91 |  
 | 
	
		
			
			| 84 | 92 |      const newWorkspaceId = parseInt(match.params.idws)
 | 
	
		
			
			| 85 |  | -    prevState.workspaceIdInUrl !== newWorkspaceId && this.setState({workspaceIdInUrl: newWorkspaceId})
 | 
	
		
			
			|  | 93 | +    if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
 | 
	
		
			
			| 86 | 94 |  
 | 
	
		
			
			| 87 | 95 |      if (user.id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, newWorkspaceId))
 | 
	
		
			
			| 88 |  | -  }
 | 
	
		
			
			| 89 | 96 |  
 | 
	
		
			
			| 90 |  | -  handleClickContentItem = content => {
 | 
	
		
			
			| 91 |  | -    this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
 | 
	
		
			
			| 92 |  | -    this.props.renderApp(this.props.app[content.type], this.props.user, {...content, workspace: this.props.workspace})
 | 
	
		
			
			|  | 97 | +    if (match.params.idcts) { // if a content id is in url, open it
 | 
	
		
			
			|  | 98 | +      const contentToOpen = workspace.content.find(wsc => wsc.id === parseInt(match.params.idcts))
 | 
	
		
			
			|  | 99 | +      if (contentToOpen === undefined) return
 | 
	
		
			
			|  | 100 | +
 | 
	
		
			
			|  | 101 | +      renderApp(
 | 
	
		
			
			|  | 102 | +        app[contentToOpen.type],
 | 
	
		
			
			|  | 103 | +        user,
 | 
	
		
			
			|  | 104 | +        {...contentToOpen, workspace: workspace}
 | 
	
		
			
			|  | 105 | +      )
 | 
	
		
			
			|  | 106 | +    }
 | 
	
		
			
			| 93 | 107 |    }
 | 
	
		
			
			| 94 | 108 |  
 | 
	
		
			
			|  | 109 | +  handleClickContentItem = content => this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
 | 
	
		
			
			|  | 110 | +
 | 
	
		
			
			| 95 | 111 |    handleClickEditContentItem = (e, content) => {
 | 
	
		
			
			| 96 | 112 |      e.stopPropagation()
 | 
	
		
			
			| 97 | 113 |      console.log('edit nyi', content)
 | 
	
	
		
			
			|  | @@ -121,21 +137,9 @@ class WorkspaceContent extends React.Component {
 | 
	
		
			
			| 121 | 137 |      this.props.dispatch(getFolderContent(this.props.workspace.id, folderId))
 | 
	
		
			
			| 122 | 138 |    }
 | 
	
		
			
			| 123 | 139 |  
 | 
	
		
			
			| 124 |  | -  handleClickCreateContent = (folder, contentType) => this.setState({
 | 
	
		
			
			| 125 |  | -    popupCreateContent: {
 | 
	
		
			
			| 126 |  | -      display: true,
 | 
	
		
			
			| 127 |  | -      type: contentType,
 | 
	
		
			
			| 128 |  | -      folder: folder
 | 
	
		
			
			| 129 |  | -    }
 | 
	
		
			
			| 130 |  | -  })
 | 
	
		
			
			| 131 |  | -
 | 
	
		
			
			| 132 |  | -  handleClosePopupCreateContent = () => this.setState({
 | 
	
		
			
			| 133 |  | -    popupCreateContent: {
 | 
	
		
			
			| 134 |  | -      display: false,
 | 
	
		
			
			| 135 |  | -      type: undefined,
 | 
	
		
			
			| 136 |  | -      folder: undefined
 | 
	
		
			
			| 137 |  | -    }
 | 
	
		
			
			| 138 |  | -  })
 | 
	
		
			
			|  | 140 | +  handleClickCreateContent = (folder, contentType) => {
 | 
	
		
			
			|  | 141 | +    this.props.renderCreateContentApp(this.props.app[contentType], this.props.user, folder)
 | 
	
		
			
			|  | 142 | +  }
 | 
	
		
			
			| 139 | 143 |  
 | 
	
		
			
			| 140 | 144 |    render () {
 | 
	
		
			
			| 141 | 145 |      const { workspace, app } = this.props
 | 
	
	
		
			
			|  | @@ -162,13 +166,7 @@ class WorkspaceContent extends React.Component {
 | 
	
		
			
			| 162 | 166 |            </PageTitle>
 | 
	
		
			
			| 163 | 167 |  
 | 
	
		
			
			| 164 | 168 |            <PageContent parentClass='workspace__content'>
 | 
	
		
			
			| 165 |  | -            { this.state.popupCreateContent.display &&
 | 
	
		
			
			| 166 |  | -              <PopupCreateContent
 | 
	
		
			
			| 167 |  | -                type={this.state.popupCreateContent.type}
 | 
	
		
			
			| 168 |  | -                folder={this.state.popupCreateContent.folder}
 | 
	
		
			
			| 169 |  | -                onClose={this.handleClosePopupCreateContent}
 | 
	
		
			
			| 170 |  | -              />
 | 
	
		
			
			| 171 |  | -            }
 | 
	
		
			
			|  | 169 | +            <div id='popupCreateContentContainer' />
 | 
	
		
			
			| 172 | 170 |  
 | 
	
		
			
			| 173 | 171 |              <div className='workspace__content__fileandfolder folder__content active'>
 | 
	
		
			
			| 174 | 172 |                <ContentItemHeader />
 |