Skip to content

Commit

Permalink
Likes and sharing panel is independent plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Apr 15, 2019
1 parent 2ee71b5 commit 63d3865
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 71 deletions.
9 changes: 1 addition & 8 deletions extensions/blocks/likes/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/**
* Internal dependencies
*/
import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';
import LikesCheckbox from './likes-checkbox';

export const name = 'likes';

export const settings = {
render: ( { props } ) => (
<JetpackLikesAndSharingPanel>
<LikesCheckbox props={ props } />
</JetpackLikesAndSharingPanel>
),
};
export const settings = { render: LikesCheckbox };
21 changes: 14 additions & 7 deletions extensions/blocks/likes/likes-checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import { CheckboxControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';

const LikesCheckbox = ( { areLikesEnabled, editPost } ) => (
<CheckboxControl
label={ __( 'Show likes.', 'jetpack' ) }
checked={ areLikesEnabled }
onChange={ value => {
editPost( { jetpack_likes_enabled: value } );
} }
/>
<JetpackLikesAndSharingPanel>
<CheckboxControl
label={ __( 'Show likes.', 'jetpack' ) }
checked={ areLikesEnabled }
onChange={ value => {
editPost( { jetpack_likes_enabled: value } );
} }
/>
</JetpackLikesAndSharingPanel>
);

// Fetch the post meta.
Expand Down
9 changes: 1 addition & 8 deletions extensions/blocks/sharing/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/**
* Internal dependencies
*/
import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';
import SharingCheckbox from './sharing-checkbox';

export const name = 'sharing';

export const settings = {
render: ( { props } ) => (
<JetpackLikesAndSharingPanel>
<SharingCheckbox props={ props } />
</JetpackLikesAndSharingPanel>
),
};
export const settings = { render: SharingCheckbox };
21 changes: 14 additions & 7 deletions extensions/blocks/sharing/sharing-checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import { CheckboxControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';

const SharingCheckbox = ( { isSharingEnabled, editPost } ) => (
<CheckboxControl
label={ __( 'Show sharing buttons.', 'jetpack' ) }
checked={ isSharingEnabled }
onChange={ value => {
editPost( { jetpack_sharing_enabled: value } );
} }
/>
<JetpackLikesAndSharingPanel>
<CheckboxControl
label={ __( 'Show sharing buttons.', 'jetpack' ) }
checked={ isSharingEnabled }
onChange={ value => {
editPost( { jetpack_sharing_enabled: value } );
} }
/>
</JetpackLikesAndSharingPanel>
);

// Fetch the post meta.
Expand Down
38 changes: 25 additions & 13 deletions extensions/shared/jetpack-likes-and-sharing-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@
*/
import { __ } from '@wordpress/i18n';
import { createSlotFill, PanelBody } from '@wordpress/components';
import { registerPlugin } from '@wordpress/plugins';

const { Fill, Slot } = createSlotFill( 'JetpackLikesAndSharingPanel' );
/**
* Internal dependencies
*/
import JetpackPluginSidebar from './jetpack-plugin-sidebar';

const JetpackLikesAndSharingPanel = ( { children } ) => <Fill>{ children }</Fill>;
const { Fill, Slot } = createSlotFill( 'JetpackLikesAndSharingPanel' );

JetpackLikesAndSharingPanel.Slot = () => (
<Slot>
{ fills => {
if ( ! fills.length ) {
return null;
}
export { Fill as default };

return <PanelBody title={ __( 'Likes and Sharing', 'jetpack' ) }>{ fills }</PanelBody>;
} }
</Slot>
);
registerPlugin( 'jetpack-likes-and-sharing-panel', {
render() {
return (
<Slot>
{ fills => {
if ( ! fills.length ) {
return null;
}

export default JetpackLikesAndSharingPanel;
return (
<JetpackPluginSidebar>
<PanelBody title={ __( 'Likes and Sharing', 'jetpack' ) }>{ fills }</PanelBody>
</JetpackPluginSidebar>
);
} }
</Slot>
);
},
} );
49 changes: 21 additions & 28 deletions extensions/shared/jetpack-plugin-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,30 @@ import { registerPlugin } from '@wordpress/plugins';
*/
import './jetpack-plugin-sidebar.scss';
import JetpackLogo from './jetpack-logo';
import JetpackLikesAndSharingPanel from './jetpack-likes-and-sharing-panel';

const { Fill, Slot } = createSlotFill( 'JetpackPluginSidebar' );

const JetpackPluginSidebar = ( { children } ) => <Fill>{ children }</Fill>;

JetpackPluginSidebar.Slot = () => (
<Slot>
{ fills => {
const likesAndSharingPanel = <JetpackLikesAndSharingPanel.Slot />;
if ( ! fills.length && ! likesAndSharingPanel ) {
return null;
}

return (
<Fragment>
<PluginSidebarMoreMenuItem target="jetpack" icon={ <JetpackLogo /> }>
Jetpack
</PluginSidebarMoreMenuItem>
<PluginSidebar name="jetpack" title="Jetpack" icon={ <JetpackLogo /> }>
{ fills }
{ likesAndSharingPanel }
</PluginSidebar>
</Fragment>
);
} }
</Slot>
);
export { Fill as default };

registerPlugin( 'jetpack-sidebar', {
render: () => <JetpackPluginSidebar.Slot />,
} );
render: () => (
<Slot>
{ fills => {
if ( ! fills.length ) {
return null;
}

export default JetpackPluginSidebar;
return (
<Fragment>
<PluginSidebarMoreMenuItem target="jetpack" icon={ <JetpackLogo /> }>
Jetpack
</PluginSidebarMoreMenuItem>
<PluginSidebar name="jetpack" title="Jetpack" icon={ <JetpackLogo /> }>
{ fills }
</PluginSidebar>
</Fragment>
);
} }
</Slot>
),
} );

0 comments on commit 63d3865

Please sign in to comment.