import PropTypes from 'prop-types'; import React from 'react'; import { connect } from 'react-redux'; import { Link } from 'react-router'; import classNames from 'classnames'; import { withTranslation } from 'react-i18next'; import * as IDEActions from '../actions/ide'; import * as preferenceActions from '../actions/preferences'; import * as projectActions from '../actions/project'; import PlayIcon from '../../../images/play.svg'; import StopIcon from '../../../images/stop.svg'; import PreferencesIcon from '../../../images/preferences.svg'; import EditProjectNameIcon from '../../../images/pencil.svg'; class Toolbar extends React.Component { constructor(props) { super(props); this.handleKeyPress = this.handleKeyPress.bind(this); this.handleProjectNameChange = this.handleProjectNameChange.bind(this); this.handleProjectNameSave = this.handleProjectNameSave.bind(this); this.state = { projectNameInputValue: props.project.name, }; } handleKeyPress(event) { if (event.key === 'Enter') { this.props.hideEditProjectName(); this.projectNameInput.blur(); } } handleProjectNameChange(event) { this.setState({ projectNameInputValue: event.target.value }); } handleProjectNameSave() { const newProjectName = this.state.projectNameInputValue.trim(); if (newProjectName.length === 0) { this.setState({ projectNameInputValue: this.props.project.name, }); } else { this.props.setProjectName(newProjectName); this.props.hideEditProjectName(); if (this.props.project.id) { this.props.saveProject(); } } } canEditProjectName() { return (this.props.owner && this.props.owner.username && this.props.owner.username === this.props.currentUser) || !this.props.owner || !this.props.owner.username; } render() { const playButtonClass = classNames({ 'toolbar__play-button': true, 'toolbar__play-button--selected': this.props.isPlaying, 'toolbar__play-button--saved': this.props.isSaved, 'toolbar__play-button--unsaved': !this.props.isSaved }); const stopButtonClass = classNames({ 'toolbar__stop-button': true, 'toolbar__stop-button--selected': !this.props.isPlaying }); const preferencesButtonClass = classNames({ 'toolbar__preferences-button': true, 'toolbar__preferences-button--selected': this.props.preferencesIsVisible }); const nameContainerClass = classNames({ 'toolbar__project-name-container': true, 'toolbar__project-name-container--editing': this.props.project.isEditingName }); const canEditProjectName = this.canEditProjectName(); return (
by {this.props.owner.username}
); } })()}