From 648882209042188d47ea5e38a1509f29bc61e3bb Mon Sep 17 00:00:00 2001 From: Jure Triglav <juretriglav@gmail.com> Date: Mon, 14 Dec 2015 18:23:37 +0100 Subject: [PATCH] Add author and date fields to BlogManager and BlogpostCreator. --- app/components/Admin/Blogpost.jsx | 28 ++++++++++++++--- app/components/Admin/BlogpostCreator.jsx | 40 +++++++++++++++++++----- app/containers/Admin.jsx | 4 ++- app/containers/Admin/BlogManager.jsx | 3 +- 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/app/components/Admin/Blogpost.jsx b/app/components/Admin/Blogpost.jsx index dcf277f1d..bd1054b4f 100644 --- a/app/components/Admin/Blogpost.jsx +++ b/app/components/Admin/Blogpost.jsx @@ -27,6 +27,7 @@ export default class Blogpost extends React.Component { _onPublish () { this.props.update(Object.assign(this.props.blogpost, { + published_at: new Date(), status: 'published' })) } @@ -56,6 +57,22 @@ export default class Blogpost extends React.Component { value={blogpost.title} /> } + + var changePublished + if (blogpost.status === 'unpublished') { + changePublished = <Button title='Publish' aria-label='Publish' bsStyle='success' onClick={this._onPublish}> + <i className='fa fa-chain'></i> + </Button> + } else { + changePublished = <Button title='Unpublish' aria-label='Unpublish' bsStyle='warning' onClick={this._onUnpublish}> + <i className='fa fa-chain-broken'></i> + </Button> + } + + if (blogpost.published_at) { + blogpost.published_at = new Date(blogpost.published_at).toDateString() + } + return ( <tr className='blogpost' key={blogpost.key}> <td> @@ -75,11 +92,14 @@ export default class Blogpost extends React.Component { </td> <td> <LinkContainer to={`/admin/editor/${blogpost._id}`}> - <Button bsStyle='primary'>Edit this</Button> + <Button bsStyle='primary' title='Edit' aria-label='Edit'> + <i className='fa fa-pencil'></i> + </Button> </LinkContainer> - <Button bsStyle='success' onClick={this._onPublish}>Publish</Button> - <Button bsStyle='warning' onClick={this._onUnpublish}>Unpublish</Button> - <Button bsStyle='danger' onClick={this._onDestroyClick}>Delete</Button> + {changePublished} + <Button bsStyle='danger' onClick={this._onDestroyClick} title='Delete' aria-label='Delete'> + <i className='fa fa-trash-o'></i> + </Button> </td> </tr> ) diff --git a/app/components/Admin/BlogpostCreator.jsx b/app/components/Admin/BlogpostCreator.jsx index 198f57270..7c2f7b14a 100644 --- a/app/components/Admin/BlogpostCreator.jsx +++ b/app/components/Admin/BlogpostCreator.jsx @@ -1,28 +1,52 @@ import React from 'react' -import TextInput from './TextInput' - -import styles from '../../scss/components/_blogpostCreator' +// import TextInput from './TextInput' +import { Input, Button } from 'react-bootstrap' export default class BlogpostCreator extends React.Component { constructor (props) { super(props) - this._onSave = this._onSave.bind(this) + this.onSave = this.onSave.bind(this) + this.onChange = this.onChange.bind(this) } - _onSave (text) { + onSave (text) { this.props.create({ type: 'blogpost', - title: text, + title: this.state.title, + author: this.state.author, status: 'unpublished', source: '' }) } + onChange () { + this.setState({ + title: this.refs.title.getValue(), + author: this.refs.author.getValue() + }) + } + render () { return ( <div> - <h1 className={styles.entrybox__header}>Create a new blog post</h1> - <TextInput className={styles.entrybox__input} placeholder='Title' onSave={this._onSave} /> + <h3>Create a new blog post</h3> + <Input + type='text' + placeholder='One fine day...' + label='Title' + ref='title' + onChange={this.onChange} + /> + <Input + type='text' + placeholder='Benjamin Franklin' + label='Author' + ref='author' + onChange={this.onChange} + /> + <Button bsStyle='primary' onClick={this.onSave} title='Create' aria-label='Create'> + <i className='fa fa-plus'></i> Create + </Button> </div> ) } diff --git a/app/containers/Admin.jsx b/app/containers/Admin.jsx index f16c2c9dd..327a499ec 100644 --- a/app/containers/Admin.jsx +++ b/app/containers/Admin.jsx @@ -16,7 +16,9 @@ class Admin extends Component { const { children } = this.props return ( <div> - <Navigation /> + <div className='bootstrap'> + <Navigation/> + </div> {children} </div> ) diff --git a/app/containers/Admin/BlogManager.jsx b/app/containers/Admin/BlogManager.jsx index c6497c1a4..3d517700d 100644 --- a/app/containers/Admin/BlogManager.jsx +++ b/app/containers/Admin/BlogManager.jsx @@ -17,11 +17,12 @@ class BlogManager extends React.Component { return ( <Grid> <div blog={blog} className={styles.vote}> - <BlogpostCreator create={actions.createFragment} /> <BlogpostList update={actions.updateFragment} delete={actions.deleteFragment} blogposts={blogposts} /> + <BlogpostCreator create={actions.createFragment} /> + </div> </Grid> ) -- GitLab