-
Notifications
You must be signed in to change notification settings - Fork 379
Client refactoring #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7dfd00a
Remove unused karma stuff
alex35mil de7627f
Remove unused gulp and setup npm lint scripts
alex35mil ede0a5e
Split generated webpack js bundle in 2: application and vendor libs
alex35mil 555453c
Update root package.json
alex35mil 95bc93e
Update root package.json
alex35mil 5be79fd
Use npm run to run client scripts
alex35mil 44eeb47
Fix after-rebase errors
alex35mil 537c985
Move js app to /client/app dir, update structure, fix linter and styl...
alex35mil 76a7482
:see_no_evil:
alex35mil 06fc11e
Pass initial data from Rails to Redux store
alex35mil 3d68653
Fix linter error
alex35mil 57f3bad
Update react_on_rails gem
alex35mil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move js app to /client/app dir, update structure, fix linter and styl...
...istic issues
- Loading branch information
commit 537c985dc82faee333d80509343ca32a3965f9dd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
client/.jscsrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| { | ||
| "preset": "airbnb", | ||
| "fileExtensions": [".js", ".jsx"], | ||
| "excludeFiles": ["build/**", "node_modules/**"] | ||
| "excludeFiles": ["build/**", "node_modules/**"], | ||
|
|
||
| "validateQuoteMarks": null // Issue with JSX quotemarks: https://github.com/jscs-dev/babel-jscs/issues/12 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
client/app/components/Comment.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React, { PropTypes } from 'react'; | ||
| import marked from 'marked'; | ||
|
|
||
| const Comment = React.createClass({ | ||
| displayName: 'Comment', | ||
|
|
||
| propTypes: { | ||
| author: PropTypes.string.isRequired, | ||
| text: PropTypes.string.isRequired, | ||
| }, | ||
|
|
||
| render() { | ||
| const { author, text } = this.props; | ||
| const rawMarkup = marked(text, { gfm: true, sanitize: true }); | ||
| return ( | ||
| <div className="comment"> | ||
| <h2 className="comment-author"> | ||
| {author} | ||
| </h2> | ||
| <span dangerouslySetInnerHTML={{__html: rawMarkup}}/> | ||
| </div> | ||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| export default Comment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 244 additions & 0 deletions
client/app/components/CommentForm.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| import React, { PropTypes } from 'react'; | ||
| import Input from 'react-bootstrap/lib/Input'; | ||
| import Row from 'react-bootstrap/lib/Row'; | ||
| import Col from 'react-bootstrap/lib/Col'; | ||
| import Nav from 'react-bootstrap/lib/Nav'; | ||
| import NavItem from 'react-bootstrap/lib/NavItem'; | ||
| import Alert from 'react-bootstrap/lib/Alert'; | ||
| import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup'; | ||
|
|
||
| const emptyComment = { author: '', text: '' }; | ||
| const textPlaceholder = 'Say something using markdown...'; | ||
|
|
||
| const CommentForm = React.createClass({ | ||
| displayName: 'CommentForm', | ||
|
|
||
| propTypes: { | ||
| ajaxSending: PropTypes.bool.isRequired, | ||
| actions: PropTypes.object.isRequired, | ||
| error: PropTypes.any, | ||
| }, | ||
|
|
||
| getInitialState() { | ||
| return { | ||
| formMode: 0, | ||
| comment: emptyComment, | ||
| }; | ||
| }, | ||
|
|
||
| handleSelect(selectedKey) { | ||
| this.setState({ formMode: selectedKey }); | ||
| }, | ||
|
|
||
| handleChange() { | ||
| let comment; | ||
|
|
||
| // This could also be done using ReactLink: | ||
| // http://facebook.github.io/react/docs/two-way-binding-helpers.html | ||
| if (this.state.formMode < 2) { | ||
| comment = { | ||
| author: this.refs.author.getValue(), | ||
| text: this.refs.text.getValue(), | ||
| }; | ||
| } else { | ||
| comment = { | ||
| // This is different because the input is a native HTML element | ||
| // rather than a React element. | ||
| author: this.refs.inlineAuthor.getDOMNode().value, | ||
| text: this.refs.inlineText.getDOMNode().value, | ||
| }; | ||
| } | ||
|
|
||
| this.setState({ comment }); | ||
| }, | ||
|
|
||
| handleSubmit(e) { | ||
| e.preventDefault(); | ||
| const { actions } = this.props; | ||
| actions | ||
| .submitComment(this.state.comment) | ||
| .then(this.resetAndFocus); | ||
| }, | ||
|
|
||
| resetAndFocus() { | ||
| // Don't reset a form that didn't submit, this results in data loss | ||
| if (this.props.error) return; | ||
|
|
||
| const comment = { author: this.state.comment.author, text: '' }; | ||
| this.setState({ comment }); | ||
|
|
||
| let ref; | ||
| if (this.state.formMode < 2) { | ||
| ref = this.refs.text.getInputDOMNode(); | ||
| } else { | ||
| ref = React.findDOMNode(this.refs.inlineText); | ||
| } | ||
|
|
||
| ref.focus(); | ||
| }, | ||
|
|
||
| formHorizontal() { | ||
| return ( | ||
| <div> | ||
| <hr /> | ||
| <form className="commentForm form-horizontal" onSubmit={this.handleSubmit}> | ||
| <Input | ||
| type="text" | ||
| label="Name" | ||
| placeholder="Your Name" | ||
| labelClassName="col-sm-2" | ||
| wrapperClassName="col-sm-10" | ||
| ref="author" | ||
| value={this.state.comment.author} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| <Input | ||
| type="textarea" | ||
| label="Text" | ||
| placeholder={textPlaceholder} | ||
| labelClassName="col-sm-2" | ||
| wrapperClassName="col-sm-10" | ||
| ref="text" | ||
| value={this.state.comment.text} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| <div className="form-group"> | ||
| <div className="col-sm-offset-2 col-sm-10"> | ||
| <input | ||
| type="submit" | ||
| className="btn btn-primary" | ||
| value="Post" | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }, | ||
|
|
||
| formStacked() { | ||
| return ( | ||
| <div> | ||
| <hr /> | ||
| <form className="commentForm form" onSubmit={this.handleSubmit}> | ||
| <Input | ||
| type="text" | ||
| label="Name" | ||
| placeholder="Your Name" | ||
| ref="author" | ||
| value={this.state.comment.author} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| <Input | ||
| type="textarea" | ||
| label="Text" | ||
| placeholder={textPlaceholder} | ||
| ref="text" | ||
| value={this.state.comment.text} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| <input | ||
| type="submit" | ||
| className="btn btn-primary" | ||
| value="Post" | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }, | ||
|
|
||
| formInline() { | ||
| return ( | ||
| <div> | ||
| <hr /> | ||
| <form className="commentForm form" onSubmit={this.handleSubmit}> | ||
| <Input label="Inline Form" wrapperClassName="wrapper"> | ||
| <Row> | ||
| <Col xs={3}> | ||
| <input | ||
| type="text" | ||
| className="form-control" | ||
| placeholder="Your Name" | ||
| ref="inlineAuthor" | ||
| value={this.state.comment.author} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| </Col> | ||
| <Col xs={8}> | ||
| <input | ||
| type="text" | ||
| className="form-control" | ||
| placeholder={textPlaceholder} | ||
| ref="inlineText" | ||
| value={this.state.comment.text} | ||
| onChange={this.handleChange} | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| </Col> | ||
| <Col xs={1}> | ||
| <input | ||
| type="submit" | ||
| className="btn btn-primary" | ||
| value="Post" | ||
| disabled={this.props.ajaxSending} | ||
| /> | ||
| </Col> | ||
| </Row> | ||
| </Input> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }, | ||
|
|
||
| errorWarning() { | ||
| // If there is no error, there is nothing to add to the DOM | ||
| if (!this.props.error) return undefined; | ||
| return ( | ||
| <Alert bsStyle="danger" key="commentSubmissionError"> | ||
| <strong>Your comment was not saved!</strong> | ||
| A server error prevented your comment from being saved. Please try again. | ||
| </Alert> | ||
| ); | ||
| }, | ||
|
|
||
| render() { | ||
| let inputForm; | ||
| switch (this.state.formMode) { | ||
| case 0: | ||
| inputForm = this.formHorizontal(); | ||
| break; | ||
| case 1: | ||
| inputForm = this.formStacked(); | ||
| break; | ||
| case 2: | ||
| inputForm = this.formInline(); | ||
| break; | ||
| default: | ||
| throw new Error(`Unknown form mode: ${this.state.formMode}.`); | ||
| } | ||
| return ( | ||
| <div> | ||
|
|
||
| <ReactCSSTransitionGroup transitionName="element"> | ||
| {this.errorWarning()} | ||
| </ReactCSSTransitionGroup> | ||
|
|
||
| <Nav bsStyle="pills" activeKey={this.state.formMode} onSelect={this.handleSelect}> | ||
| <NavItem eventKey={0}>Horizontal Form</NavItem> | ||
| <NavItem eventKey={1}>Stacked Form</NavItem> | ||
| <NavItem eventKey={2}>Inline Form</NavItem> | ||
| </Nav> | ||
| {inputForm} | ||
| </div> | ||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| export default CommentForm; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.