Fix cloning when editing someone else's project

This commit is contained in:
Ruben van de Ven 2020-10-12 17:25:26 +02:00
parent b231b6b7e3
commit fa5e7cceb1
4 changed files with 9 additions and 5 deletions

View file

@ -262,7 +262,7 @@ function generateNewIdsForChildren(file, files) {
export function cloneProject(id) { export function cloneProject(id) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch(setUnsavedChanges(false)); dispatch(setUnsavedChanges(false));
new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!id) { if (!id) {
resolve(getState()); resolve(getState());
} else { } else {

View file

@ -58,11 +58,14 @@ class Toolbar extends React.Component {
} }
render() { render() {
const canEditProjectName = this.canEditProjectName();
const playButtonClass = classNames({ const playButtonClass = classNames({
'toolbar__play-button': true, 'toolbar__play-button': true,
'toolbar__play-button--selected': this.props.isPlaying, 'toolbar__play-button--selected': this.props.isPlaying,
'toolbar__play-button--saved': this.props.isSaved, 'toolbar__play-button--saved': this.props.isSaved,
'toolbar__play-button--unsaved': !this.props.isSaved 'toolbar__play-button--unsaved': !this.props.isSaved,
'toolbar__play-button--clone': this.props.unsavedChanges && !canEditProjectName
}); });
const stopButtonClass = classNames({ const stopButtonClass = classNames({
'toolbar__stop-button': true, 'toolbar__stop-button': true,
@ -77,8 +80,6 @@ class Toolbar extends React.Component {
'toolbar__project-name-container--editing': this.props.project.isEditingName 'toolbar__project-name-container--editing': this.props.project.isEditingName
}); });
const canEditProjectName = this.canEditProjectName();
return ( return (
<div className="toolbar"> <div className="toolbar">
<button <button
@ -178,6 +179,7 @@ class Toolbar extends React.Component {
Toolbar.propTypes = { Toolbar.propTypes = {
isPlaying: PropTypes.bool.isRequired, isPlaying: PropTypes.bool.isRequired,
unsavedChanges: PropTypes.bool.isRequired,
isSaved: PropTypes.bool.isRequired, isSaved: PropTypes.bool.isRequired,
preferencesIsVisible: PropTypes.bool.isRequired, preferencesIsVisible: PropTypes.bool.isRequired,
stopSketch: PropTypes.func.isRequired, stopSketch: PropTypes.func.isRequired,
@ -221,6 +223,7 @@ function mapStateToProps(state) {
isSaved: state.project.updatedAt !== '', isSaved: state.project.updatedAt !== '',
preferencesIsVisible: state.ide.preferencesIsVisible, preferencesIsVisible: state.ide.preferencesIsVisible,
project: state.project, project: state.project,
unsavedChanges: state.ide.unsavedChanges,
}; };
} }

View file

@ -183,6 +183,7 @@ class IDEView extends React.Component {
console.trace('project to save:', this.props.project); console.trace('project to save:', this.props.project);
return this.props.saveProject(this.cmController.getContent()); return this.props.saveProject(this.cmController.getContent());
} else if (this.props.user.authenticated) { } else if (this.props.user.authenticated) {
console.log('cloning!');
return this.props.cloneProject(); return this.props.cloneProject();
} }

View file

@ -1,5 +1,5 @@
.toolbar__play-button { .toolbar__play-button {
&--unsaved { &--unsaved, &--clone {
// for some reason, I cannot manage to have PreviewFrame save _and_ actuall yload the project (it stops the playback) // for some reason, I cannot manage to have PreviewFrame save _and_ actuall yload the project (it stops the playback)
// pressing twice works. So just show a floppy the first time around :-) // pressing twice works. So just show a floppy the first time around :-)
svg { svg {