Skip to content

Commit e45334c

Browse files
fix active feedback nav;
unload projects when moving from home page to self-serve list;
1 parent c01cfba commit e45334c

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/actions/sidebar.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ export function loadProjects (filterProjectName = '', myProjects = true) {
5252
}
5353
}
5454

55+
/**
56+
* Unlads projects of the authenticated user
57+
*/
58+
export function unloadProjects () {
59+
return (dispatch) => {
60+
dispatch({
61+
type: LOAD_PROJECTS_SUCCESS,
62+
projects: []
63+
})
64+
}
65+
}
66+
5567
/**
5668
* Reset active params. e.g activeProjectId
5769
*/

src/components/Sidebar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Sidebar = ({
3333
</div>
3434
</Link>
3535
<a href='https://github.com/topcoder-platform/work-manager/issues/new' target='_blank' rel='noopener noreferrer' className='chameleon-feedback'>
36-
<div className={cn(styles.homeLink, { [styles.active]: !projectId && !selfServe })}>
36+
<div className={cn(styles.homeLink, {})}>
3737
Give Application Feedback
3838
</div>
3939
</a>

src/containers/Sidebar/index.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { Component } from 'react'
33
import PropTypes from 'prop-types'
44
import { connect } from 'react-redux'
55
import Sidebar from '../../components/Sidebar'
6-
import { loadProjects, setActiveProject, resetSidebarActiveParams } from '../../actions/sidebar'
6+
import { loadProjects, setActiveProject, resetSidebarActiveParams, unloadProjects } from '../../actions/sidebar'
77

88
class SidebarContainer extends Component {
99
constructor (props) {
@@ -26,10 +26,32 @@ class SidebarContainer extends Component {
2626
}
2727

2828
componentWillReceiveProps (nextProps) {
29-
const { projectId, isLoading } = nextProps
30-
if (this.props.projectId !== projectId && !projectId && !isLoading) {
31-
this.props.loadProjects()
29+
const { projectId, isLoading, selfServe, projects } = nextProps
30+
31+
// if we're viewing a specific project,
32+
// or we're viewing the self serve page,
33+
// or if the project is already loading,
34+
// don't load the projects
35+
if (!!projectId || selfServe || isLoading) {
36+
// if we're not in the middle of loading,
37+
// and we have projects to unload,
38+
// unload them
39+
if (!isLoading && !!projects && !!projects.length) {
40+
this.props.unloadProjects()
41+
}
42+
43+
return
3244
}
45+
46+
// if we don't have a project id
47+
// and we already have projects in the list,
48+
// don't load the projects again
49+
if (!projectId && !!projects && !!projects.length) {
50+
return
51+
}
52+
53+
// now it's okay to load the projects
54+
this.props.loadProjects()
3355
}
3456

3557
updateProjectName (val) {
@@ -38,7 +60,7 @@ class SidebarContainer extends Component {
3860
}
3961

4062
render () {
41-
const { isLoading, setActiveProject, projectId, resetSidebarActiveParams, projects } = this.props
63+
const { isLoading, setActiveProject, projectId, resetSidebarActiveParams, projects, selfServe, unloadProjects } = this.props
4264
const { searchProjectName } = this.state
4365

4466
return (
@@ -50,6 +72,8 @@ class SidebarContainer extends Component {
5072
resetSidebarActiveParams={resetSidebarActiveParams}
5173
updateProjectsList={this.updateProjectName}
5274
searchProjectName={searchProjectName}
75+
selfServe={selfServe}
76+
unloadProjects={unloadProjects}
5377
/>
5478
)
5579
}
@@ -59,6 +83,7 @@ SidebarContainer.propTypes = {
5983
projects: PropTypes.arrayOf(PropTypes.shape()),
6084
isLoading: PropTypes.bool,
6185
loadProjects: PropTypes.func,
86+
unloadProjects: PropTypes.func,
6287
activeProjectId: PropTypes.number,
6388
setActiveProject: PropTypes.func,
6489
projectId: PropTypes.string,
@@ -72,6 +97,7 @@ const mapStateToProps = ({ sidebar }) => ({
7297

7398
const mapDispatchToProps = {
7499
loadProjects,
100+
unloadProjects,
75101
setActiveProject,
76102
resetSidebarActiveParams
77103
}

0 commit comments

Comments
 (0)