Skip to content

Commit 2e71a80

Browse files
author
Vikas Agarwal
committed
Github issue#1267, Navigation small updates
— Added new project button to the details page as well. Faced interesting issue while implementing it. In the CreateContainer we are validating project.id prop in the next prop to determine if a new project has been created by the wizard. This logic was causing redirecting back to details page when user clicks on the new project button from the details page because it thinks that a new project with id of the current project is created and redirects to its details page. As a fix, now we are checking if current property value for project.id is not defined and next property value is defined to determine that new project is created. Further, we have to clear the project from the redux state when CreateContainer is mounted.
1 parent 9ce8cd3 commit 2e71a80

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/components/TopBar/ProjectToolBar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('./ProjectToolBar.scss')
22

33
import _ from 'lodash'
44
import React, {PropTypes} from 'react'
5-
import { NavLink } from 'react-router-dom'
5+
import { NavLink, Link } from 'react-router-dom'
66
import { connect } from 'react-redux'
77
import ReactDOM from 'react-dom'
88
import SVGIconImage from '../SVGIconImage'
@@ -75,6 +75,9 @@ class ProjectToolBar extends React.Component {
7575
}
7676
</ul>
7777
</nav>}
78+
<Link to="/new-project" className="new-project-link">
79+
<div className="new-project-icon"><SVGIconImage filePath="ui-16px-1_bold-add" /></div>
80+
</Link>
7881
{ userMenu }
7982
</div>
8083
</div>

src/components/TopBar/ProjectToolBar.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,33 @@
5454
}
5555
}
5656

57+
.new-project-link {
58+
display: flex;
59+
justify-content: center;
60+
flex-direction: column;
61+
align-items: center;
62+
margin-left: 20px;
63+
64+
.new-project-icon {
65+
width: 20px;
66+
height: 20px;
67+
background-color: $tc-gray-50;
68+
border-radius: 100%;
69+
display: flex;
70+
justify-content: center;
71+
align-items: center;
72+
svg {
73+
fill: $tc-black;
74+
width: 10px;
75+
height: 10px;
76+
}
77+
78+
&:hover {
79+
background-color: $tc-orange-30;
80+
}
81+
}
82+
}
83+
5784
.bar-column.project-name {
5885
span {
5986
@include roboto;

src/projects/create/containers/CreateContainer.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { PropTypes } from 'react'
44
import { withRouter } from 'react-router-dom'
55
import { connect } from 'react-redux'
66
import { renderComponent, branch, compose, withProps } from 'recompose'
7-
import { createProject as createProjectAction, fireProjectDirty, fireProjectDirtyUndo } from '../../actions/project'
7+
import { createProject as createProjectAction, fireProjectDirty, fireProjectDirtyUndo, clearLoadedProject } from '../../actions/project'
88
import CoderBot from '../../../components/CoderBot/CoderBot'
99
import spinnerWhileLoading from '../../../components/LoadingSpinner'
1010
import ProjectWizard from '../components/ProjectWizard'
@@ -65,8 +65,9 @@ class CreateConainer extends React.Component {
6565
}
6666

6767
componentWillReceiveProps(nextProps) {
68-
const projectId = _.get(nextProps, 'project.id', null)
69-
if (!nextProps.processing && !nextProps.error && projectId) {
68+
const projectId = _.get(this.props, 'project.id', null)
69+
const nextProjectId = _.get(nextProps, 'project.id', null)
70+
if (!nextProps.processing && !nextProps.error && !projectId && nextProjectId) {
7071
// update state
7172
this.setState({
7273
creatingProject: false,
@@ -75,7 +76,7 @@ class CreateConainer extends React.Component {
7576
// remove incomplete project, and navigate to project dashboard
7677
console.log('removing incomplete project')
7778
window.localStorage.removeItem(LS_INCOMPLETE_PROJECT)
78-
this.props.history.push('/projects/' + projectId)
79+
this.props.history.push('/projects/' + nextProjectId)
7980
})
8081

8182
} else if (this.state.creatingProject !== nextProps.processing) {
@@ -122,6 +123,9 @@ class CreateConainer extends React.Component {
122123
componentDidMount() {
123124
// sets window unload hook save incomplete project
124125
window.addEventListener('beforeunload', this.onLeave)
126+
// dispatches action to clear the project in the redux state to ensure that we never have a project
127+
// in context when creating a new project
128+
this.props.clearLoadedProject()
125129
}
126130

127131
componentWillUnmount() {
@@ -263,5 +267,5 @@ const mapStateToProps = ({projectState, loadUser }) => ({
263267
error: projectState.error,
264268
project: projectState.project
265269
})
266-
const actionCreators = { createProjectAction, fireProjectDirty, fireProjectDirtyUndo }
270+
const actionCreators = { createProjectAction, fireProjectDirty, fireProjectDirtyUndo, clearLoadedProject }
267271
export default withRouter(connect(mapStateToProps, actionCreators)(CreateConainer))

0 commit comments

Comments
 (0)