Skip to content

Commit

Permalink
Chrome: Fix post visbility when saving a post
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 25, 2017
1 parent 256badd commit 6115213
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function getEditedPostVisibility( state ) {

if ( status === 'private' ) {
return 'private';
} else if ( password !== undefined && password !== null ) {
} else if ( password ) {
return 'password';
}
return 'public';
Expand Down
27 changes: 20 additions & 7 deletions editor/sidebar/post-visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
import { editPost } from '../../actions';

class PostVisibility extends Component {
constructor() {
constructor( props ) {
super( ...arguments );
this.state = {
opened: false,
hasPassword: !! props.password,
};
this.toggleDialog = this.toggleDialog.bind( this );
}
Expand All @@ -43,9 +44,18 @@ class PostVisibility extends Component {
render() {
const { status, visibility, password, onUpdateVisibility } = this.props;

const setPublic = () => onUpdateVisibility( visibility === 'private' ? 'draft' : status );
const setPrivate = () => onUpdateVisibility( 'private' );
const setPasswordProtected = () => onUpdateVisibility( visibility === 'private' ? 'draft' : status, password || '' );
const setPublic = () => {
onUpdateVisibility( visibility === 'private' ? 'draft' : status );
this.setState( { hasPassword: false } );
};
const setPrivate = () => {
onUpdateVisibility( 'private' );
this.setState( { hasPassword: false } );
};
const setPasswordProtected = () => {
onUpdateVisibility( visibility === 'private' ? 'draft' : status, password || '' );
this.setState( { hasPassword: true } );
};
const updatePassword = ( event ) => onUpdateVisibility( status, event.target.value );

const visibilityOptions = [
Expand All @@ -54,18 +64,21 @@ class PostVisibility extends Component {
label: __( 'Public' ),
info: __( 'Visible to everyone.' ),
changeHandler: setPublic,
checked: visibility === 'public' && ! this.state.hasPassword,
},
{
value: 'private',
label: __( 'Private' ),
info: __( 'Only visible to site admins and editors.' ),
changeHandler: setPrivate,
checked: visibility === 'private',
},
{
value: 'password',
label: __( 'Password Protected' ),
info: __( 'Protected with a password you choose. Only those with the password can view this post.' ),
changeHandler: setPasswordProtected,
checked: this.state.hasPassword,
},
];
const getVisibilityLabel = () => find( visibilityOptions, { value: visibility } ).label;
Expand All @@ -85,14 +98,14 @@ class PostVisibility extends Component {
<div className="editor-post-visibility__dialog-legend">
{ __( 'Post Visibility' ) }
</div>
{ visibilityOptions.map( ( { value, label, info, changeHandler } ) => (
{ visibilityOptions.map( ( { value, label, info, changeHandler, checked } ) => (
<label key={ value } className="editor-post-visibility__dialog-label">
<input type="radio" value={ value } onChange={ changeHandler } checked={ value === visibility } />
<input type="radio" value={ value } onChange={ changeHandler } checked={ checked } />
{ label }
{ <div className="editor-post-visibility__dialog-info">{ info }</div> }
</label>
) ) }
{ visibility === 'password' &&
{ this.state.hasPassword &&
<input
className="editor-post-visibility__dialog-password-input"
type="text"
Expand Down

0 comments on commit 6115213

Please sign in to comment.