Skip to content

Commit

Permalink
Chrome: Adding the post excerpt panel
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 23, 2017
1 parent 3b2d42f commit 99cc1f0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
6 changes: 6 additions & 0 deletions editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export function getEditedPostTitle( state ) {
: state.editor.edits.title;
}

export function getEditedPostExcerpt( state ) {
return state.editor.edits.excerpt === undefined
? state.currentPost.excerpt.raw
: state.editor.edits.excerpt;
}

export function getEditedPostPreviewLink( state ) {
const link = state.currentPost.link;
if ( ! link ) {
Expand Down
50 changes: 50 additions & 0 deletions editor/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import PanelBody from 'components/panel/body';

/**
* Internal Dependencies
*/
import './style.scss';
import { getEditedPostExcerpt } from '../../selectors';
import { editPost } from '../../actions';

function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
const onChange = ( event ) => onUpdateExcerpt( event.target.value );

return (
<PanelBody title={ __( 'Excerpt' ) } initialOpen={ false }>
<textarea
className="editor-post-excerpt__textarea"
onChange={ onChange }
value={ excerpt }
placeholder={ __( 'Write an excerpt (optional)' ) }
/>
<a href="https://codex.wordpress.org/Excerpt" target="_blank">
{ __( 'Learn more about manual excerpts' ) }
</a>
</PanelBody>
);
/* eslint-enable jsx-a11y/label-has-for */
}

export default connect(
( state ) => ( {
excerpt: getEditedPostExcerpt( state ),
} ),
( dispatch ) => {
return {
onUpdateExcerpt( excerpt ) {
dispatch( editPost( { excerpt } ) );
},
};
}
)( PostExcerpt );

6 changes: 6 additions & 0 deletions editor/sidebar/post-excerpt/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.editor-post-excerpt__textarea {
width: 100%;
height: 80px;
margin-top: 20px;
margin-bottom: 10px;
}
2 changes: 2 additions & 0 deletions editor/sidebar/post-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import IconButton from 'components/icon-button';
*/
import './style.scss';
import PostStatus from '../post-status';
import PostExcerpt from '../post-excerpt';

const PostSettings = ( { toggleSidebar } ) => {
return (
Expand All @@ -30,6 +31,7 @@ const PostSettings = ( { toggleSidebar } ) => {
</div>
</PanelHeader>
<PostStatus />
<PostExcerpt />
</Panel>
);
};
Expand Down
29 changes: 29 additions & 0 deletions editor/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getPostEdits,
getEditedPostStatus,
getEditedPostTitle,
getEditedPostExcerpt,
getEditedPostVisibility,
getEditedPostPreviewLink,
getBlock,
Expand Down Expand Up @@ -223,6 +224,34 @@ describe( 'selectors', () => {
} );
} );

describe( 'getEditedPostExcerpt', () => {
it( 'should return the post saved excerpt if the excerpt is not edited', () => {
const state = {
currentPost: {
excerpt: { raw: 'sassel' },
},
editor: {
edits: { status: 'private' },
},
};

expect( getEditedPostExcerpt( state ) ).to.equal( 'sassel' );
} );

it( 'should return the edited excerpt', () => {
const state = {
currentPost: {
excerpt: { raw: 'sassel' },
},
editor: {
edits: { excerpt: 'youcha' },
},
};

expect( getEditedPostExcerpt( state ) ).to.equal( 'youcha' );
} );
} );

describe( 'getEditedPostVisibility', () => {
it( 'should return public by default', () => {
const state = {
Expand Down

0 comments on commit 99cc1f0

Please sign in to comment.