Commit a5b247a92047205199c0732af3f6c406aa7865c9
1 parent
5507f2d3a8
Exists in
master
Refactor hrefs to remove page loads.
Showing
3 changed files
with
20 additions
and
3 deletions
Show diff stats
imports/ui/components/DocumentsList.js
1 | import React from 'react'; | 1 | import React from 'react'; |
2 | import { browserHistory } from 'react-router'; | ||
2 | import { ListGroup, ListGroupItem, Alert } from 'react-bootstrap'; | 3 | import { ListGroup, ListGroupItem, Alert } from 'react-bootstrap'; |
3 | 4 | ||
5 | const handleNav = (_id) => { | ||
6 | browserHistory.push(`/documents/${_id}`); | ||
7 | } | ||
8 | |||
4 | const DocumentsList = ({ documents }) => ( | 9 | const DocumentsList = ({ documents }) => ( |
5 | documents.length > 0 ? <ListGroup className="DocumentsList"> | 10 | documents.length > 0 ? <ListGroup className="DocumentsList"> |
6 | {documents.map(({ _id, title }) => ( | 11 | {documents.map(({ _id, title }) => ( |
7 | <ListGroupItem key={ _id } href={`/documents/${_id}`}>{ title }</ListGroupItem> | 12 | <ListGroupItem key={ _id } onClick={ () => handleNav(_id) }> |
13 | { title } | ||
14 | </ListGroupItem> | ||
8 | ))} | 15 | ))} |
9 | </ListGroup> : | 16 | </ListGroup> : |
10 | <Alert bsStyle="warning">No documents yet.</Alert> | 17 | <Alert bsStyle="warning">No documents yet.</Alert> |
11 | ); | 18 | ); |
12 | 19 | ||
13 | DocumentsList.propTypes = { | 20 | DocumentsList.propTypes = { |
14 | documents: React.PropTypes.array, | 21 | documents: React.PropTypes.array, |
15 | }; | 22 | }; |
16 | 23 | ||
17 | export default DocumentsList; | 24 | export default DocumentsList; |
18 | 25 |
imports/ui/pages/Documents.js
1 | import React from 'react'; | 1 | import React from 'react'; |
2 | import { browserHistory } from 'react-router'; | ||
2 | import { Row, Col, Button } from 'react-bootstrap'; | 3 | import { Row, Col, Button } from 'react-bootstrap'; |
3 | import DocumentsList from '../containers/DocumentsList.js'; | 4 | import DocumentsList from '../containers/DocumentsList.js'; |
4 | 5 | ||
6 | const buttonNav = (event) => { | ||
7 | event.preventDefault(); | ||
8 | browserHistory.push('/documents/new'); | ||
9 | } | ||
10 | |||
5 | const Documents = () => ( | 11 | const Documents = () => ( |
6 | <div className="Documents"> | 12 | <div className="Documents"> |
7 | <Row> | 13 | <Row> |
8 | <Col xs={ 12 }> | 14 | <Col xs={ 12 }> |
9 | <div className="page-header clearfix"> | 15 | <div className="page-header clearfix"> |
10 | <h4 className="pull-left">Documents</h4> | 16 | <h4 className="pull-left">Documents</h4> |
11 | <Button | 17 | <Button |
12 | bsStyle="success" | 18 | bsStyle="success" |
13 | className="pull-right" | 19 | className="pull-right" |
14 | href="/documents/new" | 20 | onClick={ buttonNav } |
15 | >New Document</Button> | 21 | >New Document</Button> |
16 | </div> | 22 | </div> |
17 | <DocumentsList /> | 23 | <DocumentsList /> |
18 | </Col> | 24 | </Col> |
19 | </Row> | 25 | </Row> |
20 | </div> | 26 | </div> |
21 | ); | 27 | ); |
22 | 28 | ||
23 | export default Documents; | 29 | export default Documents; |
24 | 30 |
imports/ui/pages/ViewDocument.js
1 | import React from 'react'; | 1 | import React from 'react'; |
2 | import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap'; | 2 | import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap'; |
3 | import { browserHistory } from 'react-router'; | 3 | import { browserHistory } from 'react-router'; |
4 | import { Bert } from 'meteor/themeteorchef:bert'; | 4 | import { Bert } from 'meteor/themeteorchef:bert'; |
5 | import { removeDocument } from '../../api/documents/methods.js'; | 5 | import { removeDocument } from '../../api/documents/methods.js'; |
6 | 6 | ||
7 | const handleEdit = (_id) => { | ||
8 | browserHistory.push(`/documents/${_id}/edit`); | ||
9 | } | ||
10 | |||
7 | const handleRemove = (_id) => { | 11 | const handleRemove = (_id) => { |
8 | if (confirm('Are you sure? This is permanent!')) { | 12 | if (confirm('Are you sure? This is permanent!')) { |
9 | removeDocument.call({ _id }, (error) => { | 13 | removeDocument.call({ _id }, (error) => { |
10 | if (error) { | 14 | if (error) { |
11 | Bert.alert(error.reason, 'danger'); | 15 | Bert.alert(error.reason, 'danger'); |
12 | } else { | 16 | } else { |
13 | Bert.alert('Document deleted!', 'success'); | 17 | Bert.alert('Document deleted!', 'success'); |
14 | browserHistory.push('/documents'); | 18 | browserHistory.push('/documents'); |
15 | } | 19 | } |
16 | }); | 20 | }); |
17 | } | 21 | } |
18 | }; | 22 | }; |
19 | 23 | ||
20 | const ViewDocument = ({ doc }) => ( | 24 | const ViewDocument = ({ doc }) => ( |
21 | <div className="ViewDocument"> | 25 | <div className="ViewDocument"> |
22 | <div className="page-header clearfix"> | 26 | <div className="page-header clearfix"> |
23 | <h4 className="pull-left">{ doc.title }</h4> | 27 | <h4 className="pull-left">{ doc.title }</h4> |
24 | <ButtonToolbar className="pull-right"> | 28 | <ButtonToolbar className="pull-right"> |
25 | <ButtonGroup bsSize="small"> | 29 | <ButtonGroup bsSize="small"> |
26 | <Button href={`/documents/${doc._id}/edit`}>Edit</Button> | 30 | <Button onClick={ () => handleEdit(doc._id) }>Edit</Button> |
27 | <Button onClick={ () => handleRemove(doc._id) } className="text-danger">Delete</Button> | 31 | <Button onClick={ () => handleRemove(doc._id) } className="text-danger">Delete</Button> |
28 | </ButtonGroup> | 32 | </ButtonGroup> |
29 | </ButtonToolbar> | 33 | </ButtonToolbar> |
30 | </div> | 34 | </div> |
31 | { doc.body } | 35 | { doc.body } |
32 | </div> | 36 | </div> |
33 | ); | 37 | ); |
34 | 38 | ||
35 | ViewDocument.propTypes = { | 39 | ViewDocument.propTypes = { |
36 | doc: React.PropTypes.object.isRequired, | 40 | doc: React.PropTypes.object.isRequired, |
37 | }; | 41 | }; |
38 | 42 | ||
39 | export default ViewDocument; | 43 | export default ViewDocument; |
40 | 44 |