This commit is contained in:
Cassie Tarakajian 2016-11-04 18:54:14 -04:00
parent dd01aeb599
commit 41c1613d10
2 changed files with 23 additions and 7 deletions

View file

@ -31,6 +31,12 @@ class Toolbar extends React.Component {
} }
} }
canEditProjectName() {
return (this.props.owner && this.props.owner.username
&& this.props.owner.username === this.props.currentUser)
|| !this.props.owner || !this.props.owner.username;
}
render() { render() {
let playButtonClass = classNames({ let playButtonClass = classNames({
'toolbar__play-button': true, 'toolbar__play-button': true,
@ -89,12 +95,19 @@ class Toolbar extends React.Component {
<div className={nameContainerClass}> <div className={nameContainerClass}>
<a <a
className="toolbar__project-name" className="toolbar__project-name"
onClick={() => { href={`/projects/${this.props.project.id}`}
onClick={(e) => {
if (this.canEditProjectName()) {
e.preventDefault();
this.originalProjectName = this.props.project.name; this.originalProjectName = this.props.project.name;
this.props.showEditProjectName(); this.props.showEditProjectName();
setTimeout(() => this.refs.projectNameInput.focus(), 0); setTimeout(() => this.refs.projectNameInput.focus(), 0);
}
}} }}
>{this.props.project.name} <InlineSVG className="toolbar__edit-name-button" src={editProjectNameUrl} alt="Edit Project Name" /></a> >
{this.props.project.name}&nbsp;
{this.canEditProjectName() && <InlineSVG className="toolbar__edit-name-button" src={editProjectNameUrl} alt="Edit Project Name" />}
</a>
<input <input
type="text" type="text"
className="toolbar__project-name-input" className="toolbar__project-name-input"
@ -155,7 +168,8 @@ Toolbar.propTypes = {
autorefresh: PropTypes.bool.isRequired, autorefresh: PropTypes.bool.isRequired,
setAutorefresh: PropTypes.func.isRequired, setAutorefresh: PropTypes.func.isRequired,
startSketchAndRefresh: PropTypes.func.isRequired, startSketchAndRefresh: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired saveProject: PropTypes.func.isRequired,
currentUser: PropTypes.string
}; };
export default Toolbar; export default Toolbar;

View file

@ -201,6 +201,7 @@ class IDEView extends React.Component {
setAutorefresh={this.props.setAutorefresh} setAutorefresh={this.props.setAutorefresh}
startSketchAndRefresh={this.props.startSketchAndRefresh} startSketchAndRefresh={this.props.startSketchAndRefresh}
saveProject={this.props.saveProject} saveProject={this.props.saveProject}
currentUser={this.props.user.username}
/> />
<Preferences <Preferences
isVisible={this.props.ide.preferencesIsVisible} isVisible={this.props.ide.preferencesIsVisible}
@ -451,7 +452,8 @@ IDEView.propTypes = {
getProject: PropTypes.func.isRequired, getProject: PropTypes.func.isRequired,
user: PropTypes.shape({ user: PropTypes.shape({
authenticated: PropTypes.bool.isRequired, authenticated: PropTypes.bool.isRequired,
id: PropTypes.string id: PropTypes.string,
username: PropTypes.string
}).isRequired, }).isRequired,
newProject: PropTypes.func.isRequired, newProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired, saveProject: PropTypes.func.isRequired,