From d072a3eaa871ec26cf1eabbaa7ca258c501a8b09 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 4 Sep 2019 12:59:41 -0400 Subject: [PATCH] feat: update getDocument to use new writer.getDocument format --- src/SaveToPath.js | 37 +++++++++++++++++++------------------ src/index.js | 7 +++++-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/SaveToPath.js b/src/SaveToPath.js index 8909812..1148a45 100644 --- a/src/SaveToPath.js +++ b/src/SaveToPath.js @@ -122,26 +122,27 @@ class SaveToPath extends Component { save = () => { this.setState({saving: true}); - const document = this.props.getDocument(); - this.props.usePR ? - cwrcGit.saveAsPullRequest(this.getFullRepoPath(), this.props.path, document, this.state.prBranch, this.state.commitMessage, this.state.prTitle).then( - (result) => this.complete(), - (error) => { - if (error.statusText === 'Internal Server Error') { - error.statusText = 'You do not have pull request permissions for the selected repository. Try saving to another repository you have pull request privileges for.' + this.props.getDocument().then((document) => { + this.props.usePR ? + cwrcGit.saveAsPullRequest(this.getFullRepoPath(), this.props.path, document, this.state.prBranch, this.state.commitMessage, this.state.prTitle).then( + (result) => this.complete(), + (error) => { + if (error.statusText === 'Internal Server Error') { + error.statusText = 'You do not have pull request permissions for the selected repository. Try saving to another repository you have pull request privileges for.' + } + this.displayError(error) } - this.displayError(error) - } - ) : - cwrcGit.saveDoc(this.getFullRepoPath(), this.props.path, document, this.state.branch, this.state.commitMessage).then( - (result) => this.complete(), - (error) => { - if (error.statusText === 'Not Found') { - error.statusText = 'You do not have writing permissions for the selected repository. Try saving as a pull request or save to another repository you have writing privileges for.' + ) : + cwrcGit.saveDoc(this.getFullRepoPath(), this.props.path, document, this.state.branch, this.state.commitMessage).then( + (result) => this.complete(), + (error) => { + if (error.statusText === 'Not Found') { + error.statusText = 'You do not have writing permissions for the selected repository. Try saving as a pull request or save to another repository you have writing privileges for.' + } + this.displayError(error) } - this.displayError(error) - } - ) + ) + }) } diff --git a/src/index.js b/src/index.js index 7114df6..1984b90 100644 --- a/src/index.js +++ b/src/index.js @@ -112,8 +112,11 @@ function getDocumentURI() { } function getDocument() { - const content = _writer.getDocument(true); - return content; + return new Promise((resolve, reject) => { + _writer.getDocumentString((content) => { + resolve(content); + }); + }) } function getDocumentInfoFromLocation() {