Skip to content
Snippets Groups Projects
Commit 79de37a4 authored by Alf Eaton's avatar Alf Eaton Committed by john
Browse files

Allow books to be created

parent 6ef05881
No related branches found
No related tags found
No related merge requests found
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { Modal } from 'react-bootstrap' import { Modal, Button, FormControl, FormGroup, ControlLabel } from 'react-bootstrap'
import { LinkContainer } from 'react-router-bootstrap'
import * as Actions from 'pubsweet-frontend/src/actions' import * as Actions from 'pubsweet-frontend/src/actions'
import { Link } from 'react-router'
import styles from './styles/bookList.local.scss' import styles from './styles/bookList.local.scss'
export class BookList extends React.Component { export class BookList extends React.Component {
...@@ -23,16 +24,34 @@ export class BookList extends React.Component { ...@@ -23,16 +24,34 @@ export class BookList extends React.Component {
}) })
} }
_createCollection = (event) => {
event.preventDefault()
this.props.actions.createCollection({
title: ReactDOM.findDOMNode(this.refs.newBookTitle).value || 'Untitled'
})
// TODO: allow the title to be edited
// TODO: handle errors
this._toggleModal()
}
render () { render () {
const { book } = this.props const { books } = this.props
const { showModal } = this.state const { showModal } = this.state
let bookTitle = book ? book.title : 'Fetching...'
let bookId = book ? book.id : '' // TODO: sort most recently created to the top
// TODO: needs a "created_at" property on each book
// if (books) {
// books.sort((a, b) => {
// return (b.created_at < a.created_at) ? -1 : ((b.created_at > a.created_at) ? 1 : 0);
// })
// }
return ( return (
<div className={styles.bookList + ' bootstrap'}> <div className={styles.bookList + ' bootstrap'}>
{/* FIXME: make this height: 100%, overflow: auto so it scrolls */}
<div className='container col-lg-offset-2 col-lg-8'> <div className='container col-lg-offset-2 col-lg-8'>
{ /* FIXME: make this a fixed header */ }
<div className='col-lg-12'> <div className='col-lg-12'>
<h1 className={styles.bookTitle}> <h1 className={styles.bookTitle}>
Books Books
...@@ -43,17 +62,12 @@ export class BookList extends React.Component { ...@@ -43,17 +62,12 @@ export class BookList extends React.Component {
</div> </div>
<div className='col-lg-12'> <div className='col-lg-12'>
<div className={styles.bookContainer}> {books ? books.map(book => (
<h2>{bookTitle}</h2> <div key={book.id} className={styles.bookContainer}>
<LinkContainer to={`/books/${bookId}/book-builder`}> <h2>{book.title}</h2>
<a href='#' <Link to={`/books/${book.id}/book-builder`} className={styles.editBook}>Edit</Link>
className={styles.editBook} </div>
onClick={this._toggleModal} > )) : 'Fetching…' }
Edit
</a>
</LinkContainer>
</div>
</div> </div>
</div> </div>
...@@ -71,7 +85,16 @@ export class BookList extends React.Component { ...@@ -71,7 +85,16 @@ export class BookList extends React.Component {
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>
This feature is currently disabled. <form onSubmit={this._createCollection}>
<FormGroup>
<ControlLabel>Title</ControlLabel>
<FormControl ref="newBookTitle" name="title" type="text" placeholder="Untitled"/>
</FormGroup>
<Button bsStyle="primary" type="submit">
<i className='fa fa-plus'/> Create book
</Button>
</form>
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>
...@@ -89,12 +112,13 @@ export class BookList extends React.Component { ...@@ -89,12 +112,13 @@ export class BookList extends React.Component {
} }
BookList.propTypes = { BookList.propTypes = {
book: React.PropTypes.object books: React.PropTypes.arrayOf(React.PropTypes.object),
actions: React.PropTypes.object.isRequired
} }
function mapStateToProps (state) { function mapStateToProps (state, { params }) {
return { return {
book: state.collections[0] books: state.collections
} }
} }
......
...@@ -18,6 +18,8 @@ import SimpleEditorWrapper from './components/SimpleEditor/SimpleEditorWrapper' ...@@ -18,6 +18,8 @@ import SimpleEditorWrapper from './components/SimpleEditor/SimpleEditorWrapper'
import Login from 'pubsweet-component-login/Login' import Login from 'pubsweet-component-login/Login'
import Signup from 'pubsweet-component-signup/Signup' import Signup from 'pubsweet-component-signup/Signup'
// FIXME: this shouldn't be using the collection as the object
const AuthenticatedManage = requireAuthentication( const AuthenticatedManage = requireAuthentication(
Manage, 'create', (state) => state.collections[0] Manage, 'create', (state) => state.collections[0]
) )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment