* for #790, when saving a sketch, pull from codemirror window * fix lint errors
This commit is contained in:
parent
61f20d1d4c
commit
2cc0d578fb
4 changed files with 39 additions and 25 deletions
|
@ -157,7 +157,7 @@ class Nav extends React.PureComponent {
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (this.props.user.authenticated) {
|
if (this.props.user.authenticated) {
|
||||||
this.props.saveProject();
|
this.props.saveProject(this.props.cmController.getContent());
|
||||||
} else {
|
} else {
|
||||||
this.props.showErrorModal('forceAuthentication');
|
this.props.showErrorModal('forceAuthentication');
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,8 @@ Nav.propTypes = {
|
||||||
tidyCode: PropTypes.func,
|
tidyCode: PropTypes.func,
|
||||||
showFind: PropTypes.func,
|
showFind: PropTypes.func,
|
||||||
findNext: PropTypes.func,
|
findNext: PropTypes.func,
|
||||||
findPrev: PropTypes.func
|
findPrev: PropTypes.func,
|
||||||
|
getContent: PropTypes.func
|
||||||
}),
|
}),
|
||||||
startSketch: PropTypes.func.isRequired,
|
startSketch: PropTypes.func.isRequired,
|
||||||
stopSketch: PropTypes.func.isRequired,
|
stopSketch: PropTypes.func.isRequired,
|
||||||
|
|
|
@ -66,7 +66,7 @@ export function clearPersistedState() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveProject(autosave = false) {
|
export function saveProject(selectedFile = null, autosave = false) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
if (state.user.id && state.project.owner && state.project.owner.id !== state.user.id) {
|
if (state.user.id && state.project.owner && state.project.owner.id !== state.user.id) {
|
||||||
|
@ -74,6 +74,11 @@ export function saveProject(autosave = false) {
|
||||||
}
|
}
|
||||||
const formParams = Object.assign({}, state.project);
|
const formParams = Object.assign({}, state.project);
|
||||||
formParams.files = [...state.files];
|
formParams.files = [...state.files];
|
||||||
|
if (selectedFile) {
|
||||||
|
console.log('selected file being updated');
|
||||||
|
const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id);
|
||||||
|
fileToUpdate.content = selectedFile.content;
|
||||||
|
}
|
||||||
if (state.project.id) {
|
if (state.project.id) {
|
||||||
return axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
return axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -156,7 +161,7 @@ export function saveProject(autosave = false) {
|
||||||
|
|
||||||
export function autosaveProject() {
|
export function autosaveProject() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
saveProject(true)(dispatch, getState);
|
saveProject(null, true)(dispatch, getState);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ class Editor extends React.Component {
|
||||||
this.showFind = this.showFind.bind(this);
|
this.showFind = this.showFind.bind(this);
|
||||||
this.findNext = this.findNext.bind(this);
|
this.findNext = this.findNext.bind(this);
|
||||||
this.findPrev = this.findPrev.bind(this);
|
this.findPrev = this.findPrev.bind(this);
|
||||||
|
this.getContent = this.getContent.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -144,7 +145,8 @@ class Editor extends React.Component {
|
||||||
tidyCode: this.tidyCode,
|
tidyCode: this.tidyCode,
|
||||||
showFind: this.showFind,
|
showFind: this.showFind,
|
||||||
findNext: this.findNext,
|
findNext: this.findNext,
|
||||||
findPrev: this.findPrev
|
findPrev: this.findPrev,
|
||||||
|
getContent: this.getContent
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,13 +232,24 @@ class Editor extends React.Component {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeDocuments(files) {
|
getContent() {
|
||||||
this._docs = {};
|
const content = this._cm.getValue();
|
||||||
files.forEach((file) => {
|
const updatedFile = Object.assign({}, this.props.file, { content });
|
||||||
if (file.name !== 'root') {
|
return updatedFile;
|
||||||
this._docs[file.id] = CodeMirror.Doc(file.content, this.getFileMode(file.name)); // eslint-disable-line
|
}
|
||||||
}
|
|
||||||
});
|
findPrev() {
|
||||||
|
this._cm.focus();
|
||||||
|
this._cm.execCommand('findPrev');
|
||||||
|
}
|
||||||
|
|
||||||
|
findNext() {
|
||||||
|
this._cm.focus();
|
||||||
|
this._cm.execCommand('findNext');
|
||||||
|
}
|
||||||
|
|
||||||
|
showFind() {
|
||||||
|
this._cm.execCommand('findPersistent');
|
||||||
}
|
}
|
||||||
|
|
||||||
tidyCode() {
|
tidyCode() {
|
||||||
|
@ -255,18 +268,13 @@ class Editor extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showFind() {
|
initializeDocuments(files) {
|
||||||
this._cm.execCommand('findPersistent');
|
this._docs = {};
|
||||||
}
|
files.forEach((file) => {
|
||||||
|
if (file.name !== 'root') {
|
||||||
findNext() {
|
this._docs[file.id] = CodeMirror.Doc(file.content, this.getFileMode(file.name)); // eslint-disable-line
|
||||||
this._cm.focus();
|
}
|
||||||
this._cm.execCommand('findNext');
|
});
|
||||||
}
|
|
||||||
|
|
||||||
findPrev() {
|
|
||||||
this._cm.focus();
|
|
||||||
this._cm.execCommand('findPrev');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleEditorOptions() {
|
toggleEditorOptions() {
|
||||||
|
|
|
@ -157,7 +157,7 @@ class IDEView extends React.Component {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (this.isUserOwner() || (this.props.user.authenticated && !this.props.project.owner)) {
|
if (this.isUserOwner() || (this.props.user.authenticated && !this.props.project.owner)) {
|
||||||
this.props.saveProject();
|
this.props.saveProject(this.cmController.getContent());
|
||||||
} else if (this.props.user.authenticated) {
|
} else if (this.props.user.authenticated) {
|
||||||
this.props.cloneProject();
|
this.props.cloneProject();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue