diff --git a/.gitignore b/.gitignore index 354a55f..ccab72a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ yarn-debug.log* yarn-error.log* personal-access-token.json -package-lock.json \ No newline at end of file +package-lock.json +.vscode \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ee4373a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "jsxBracketSameLine": true +} diff --git a/package.json b/package.json index 3bcb15a..dc0f538 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ "dependencies": { "lodash": "^4.17.4", "react": "^16.0.0", + "react-composer": "^3.0.1", "react-dom": "^16.0.0", "react-redux": "^5.0.5", + "react-redux-resource": "0.0.3", "react-router-dom": "^4.1.1", "react-scripts": "1.0.10", "redux": "^3.7.1", - "redux-resource": "^2.4.0", "redux-resource-plugins": "^2.1.0", "redux-resource-xhr": "^3.0.0", "redux-thunk": "^2.2.0", diff --git a/src/components/App.js b/src/components/App.js index 6554425..d3bb873 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -21,10 +21,9 @@ class App extends Component { New Gist - {!isLoggedIn && ( + {!isLoggedIn && `Please provide a GitHub Personal Access Token to use this application. - For more, refer to this project's documentation on GitHub.` - )} + For more, refer to this project's documentation on GitHub.`} {isLoggedIn && children} ); diff --git a/src/components/CreateGist.js b/src/components/CreateGist.js deleted file mode 100644 index 30f368e..0000000 --- a/src/components/CreateGist.js +++ /dev/null @@ -1,110 +0,0 @@ -import React, { Component } from 'react'; -import { bindActionCreators } from 'redux'; -import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; -import { getStatus, getResources } from 'redux-resource'; -import { createGist, resetCreateGistStatus } from '../state/gists/action-creators'; - -class CreateGist extends Component { - render() { - const { createGistStatus, createdGist } = this.props; - const { description } = this.state; - - return ( -
- {createGistStatus.succeeded && ( -
- Your gist was successfully created. - {' '} - - Go to Gist details. - -
- )} - {!createGistStatus.succeeded && ( -
-
- - {createGistStatus.pending && 'Creating gist...'} - {createGistStatus.failed && 'An error occurred while creating the gist.'} -
-
-
- Description: -
- -
-
- )} -
- ); - } - - state = { - description: '', - files: {} - }; - - componentWillUnmount() { - const { resetCreateGistStatus } = this.props; - - if (this.createGistXhr) { - this.createGistXhr.abort(); - } - - // We need to reset whatever the current status of the create request is - // when we navigate away. That way, users can create new gists when they - // return. - resetCreateGistStatus(); - } - - createGist = () => { - const { createGist } = this.props; - const { description } = this.state; - - this.createGistXhr = createGist({ - description, - public: true, - files: { - 'file1.txt': { - content: 'String file contents' - } - } - }); - } - - onDescriptionChange = (event) => { - this.setState({ - description: event.target.value - }); - } -} - -function mapStateToProps(state, props) { - const createGistStatus = getStatus(state, 'gists.requests.createGist.status'); - const createdGist = getResources(state.gists, 'createdGists')[0]; - - return { - createdGist, - createGistStatus - }; -} - -function mapDispatchToProps(dispatch) { - return bindActionCreators({ - createGist, - resetCreateGistStatus - }, dispatch); -} - -export default connect(mapStateToProps, mapDispatchToProps)(CreateGist); diff --git a/src/components/Gist.js b/src/components/Gist.js index f023a81..cfc9e81 100644 --- a/src/components/Gist.js +++ b/src/components/Gist.js @@ -1,69 +1,69 @@ import React, { Component } from 'react'; -import { bindActionCreators } from 'redux'; -import { connect } from 'react-redux'; -import { getStatus } from 'redux-resource'; +import Composer from 'react-composer'; import _ from 'lodash'; import './Gist.css'; -import { - readGist, updateGist, deleteGist, resetUpdateGistStatus -} from '../state/gists/action-creators'; +import { ReadGist, UpdateGist, DeleteGist } from '../request-components/Gists'; -class Gist extends Component { +// Note: see the bottom of the file for where this gets connected to the +// Redux store + +export class Gist extends Component { render() { - const { - readGistStatus, deleteGistStatus, updateGistStatus, gistNotFound - } = this.props; + const { gistId, requests } = this.props; + const { readGist, updateGist, deleteGist } = requests; const { description, files } = this.state; - // When the Gist is successfully deleted, this render function may be called - // once, or a handful of times. We can just return `null` until the page - // transition occurs. - if (deleteGistStatus.succeeded) { - return null; - } + const gist = readGist.resources[gistId]; - const changePending = updateGistStatus.pending || deleteGistStatus.pending; + const gistNotFound = readGist.request.statusCode === 404; + const changePending = + updateGist.status.pending || deleteGist.status.pending; return (
- {readGistStatus.pending && ('Loading gist...')} - {readGistStatus.failed && !gistNotFound && ( - - There was an error while retrieving this gist. - - )} - {readGistStatus.failed && gistNotFound && ('This gist could not be found.')} - {readGistStatus.succeeded && ( + {!gist && readGist.status.pending && 'Loading gist...'} + {!gist && + readGist.status.failed && + !gistNotFound && ( + + There was an error while retrieving this gist.{' '} + + + )} + {!gist && + readGist.status.failed && + gistNotFound && + 'This gist could not be found.'} + {gist && (
- {updateGistStatus.pending && 'Saving gist...'} - {updateGistStatus.succeeded && 'Saved!'} - {deleteGistStatus.pending && 'Deleting gist...'} + {updateGist.status.pending && 'Saving gist...'} + {updateGist.status.succeeded && 'Saved!'} + {deleteGist.status.pending && 'Deleting gist...'}
-
- Description: -
+
Description:
+ onChange={this.onDescriptionChange} + />
{_.map(files, (file, originalFilename) => { @@ -73,12 +73,17 @@ class Gist extends Component { type="text" className="gist_fileNameInput" value={file.filename} - onChange={(event) => this.onFileNameChange(originalFilename, event)}/> + onChange={event => + this.onFileNameChange(originalFilename, event) + } + />