From b41a8db0f81b28d22b1e9a07c1f04cba74447881 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 31 May 2019 15:45:51 -0400 Subject: [PATCH] fix: separate user and repo in save form, update splash --- src/FileUpload.js | 1 + src/Save.js | 145 +++++++++++++++++++++++--------------------- src/SaveToPath.js | 42 ++++++++----- src/Splash.js | 42 +++++++------ src/VerifyRepo.js | 30 ++++----- src/authenticate.js | 2 +- src/index.js | 13 +++- 7 files changed, 156 insertions(+), 119 deletions(-) diff --git a/src/FileUpload.js b/src/FileUpload.js index 55c8b3b..7508fa8 100644 --- a/src/FileUpload.js +++ b/src/FileUpload.js @@ -79,6 +79,7 @@ class FileUpload extends Component { { - return ( - - Document Saved - Your document has been saved. - - - - - ) -} - -const SaveForm = ({handleRepoChangeCB, handlePathChangeCB, saveFileCB, saveFileAsPullRequestCB, cancelCB, repo, path}) => { - return ( - - Save to Repository - -
- - Repository Path - - [GitHub-user-ID]/[GitHub-repository] (e.g., jchartrand/cheeses) - - - File Path - - The repository path to which to save (e.g., french/basque/SaintSauveur.xml) - -
-
- - - - - -
- ) -} - class SaveCmp extends Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); + this.saveFile = this.saveFile.bind(this); + this.saveFileAsPR = this.saveFileAsPR.bind(this); } componentWillMount() { @@ -81,6 +30,7 @@ class SaveCmp extends Component { resetState() { this.setState({ + user: this.props.user, repo: this.props.repo, path: this.props.path, usePR: false, @@ -94,6 +44,17 @@ class SaveCmp extends Component { // handles changes passed up from the form handleChange(name, value) { this.setState({[name]: value}); + switch(name) { + case 'path': + this.props.handlePathChange(value); + break; + case 'user': + this.props.handleRepoChange(value+'/'+this.state.repo); + break; + case 'repo': + this.props.handleRepoChange(this.state.user+'/'+value); + break; + } } // action on button click in form @@ -107,7 +68,8 @@ class SaveCmp extends Component { } saved() { - this.setState({saved: true}) + this.props.handleSaved(this.state.user+'/'+this.state.repo, this.state.path); + this.setState({saved: true}); } // callback passed to VerifyRepo @@ -121,30 +83,76 @@ class SaveCmp extends Component { } render() { - const {repo, path, usePR, message, submitted, repoVerified, saved} = this.state; + const {user, repo, path, usePR, message, submitted, repoVerified, saved} = this.state; const handleClose = this.props.handleClose; - const handleRepoChange = this.props.handleRepoChange; - const handlePathChange = this.props.handlePathChange; const getDocument = this.props.getDocument; if (saved) { return ( - + + Save to Repository + +

Document Saved

+

Your document has been saved.

+
+ + + +
) } else if (!submitted) { return ( - {let val = e.target.value; this.handleChange('repo', val); handleRepoChange(val);}} - handlePathChangeCB={(e)=>{let val = e.target.value; this.handleChange('path', val); handlePathChange(val);}} - repo={repo} - path={path} - saveFileCB={this.saveFile.bind(this)} - saveFileAsPullRequestCB={this.saveFileAsPR.bind(this)} - cancelCB={handleClose} - /> + + Save to Repository + +
+ + +

Repository Path

+ + + GitHub User + {this.handleChange('user', e.target.value)}}/> + + + + + Repository Name + {this.handleChange('repo', e.target.value)}}/> + + +
+ +

File Path

+ + + {this.handleChange('path', e.target.value)}}/> + The file (and folder) path to which to save (e.g., french/basque/SaintSauveur.xml) + + +
+
+
+
+ + + + + +
) } else if (submitted && !repoVerified) { return ( ( - An error occurred + Save to Repository +

An error occurred

{error}

@@ -19,12 +20,13 @@ const ErrorModal = ({cancel, error}) => ( const ConfirmModal = ({cancel, title, body, ok}) => ( - {title} + Save to Repository +

{title}

{body}

- diff --git a/src/VerifyRepo.js b/src/VerifyRepo.js index a5df852..ac5e970 100644 --- a/src/VerifyRepo.js +++ b/src/VerifyRepo.js @@ -12,19 +12,20 @@ const ErrorModal = ({cancel, error}) => ( + >Ok
) const ConfirmModal = ({cancel, title, body, ok, buttonText}) => ( - {title} + Save to Repository +

{title}

{body}

-