Skip to content

Commit cc08edc

Browse files
authored
fix(content-distribution): refactor outgoing post js (#188)
1 parent f36bb28 commit cc08edc

File tree

6 files changed

+62
-84
lines changed

6 files changed

+62
-84
lines changed

includes/content-distribution/class-editor.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public static function enqueue_block_editor_assets(): void {
8787
* @return void
8888
*/
8989
private static function enqueue_block_editor_assets_for_incoming_post( WP_Post $post ): void {
90-
9190
$incoming = new Incoming_Post( $post->ID );
9291

9392
wp_enqueue_script(
@@ -125,24 +124,24 @@ private static function enqueue_block_editor_assets_for_incoming_post( WP_Post $
125124
*/
126125
private static function enqueue_block_editor_assets_for_outgoing_post( WP_Post $post ): void {
127126
wp_enqueue_script(
128-
'newspack-network-distribute',
129-
plugins_url( '../../dist/distribute.js', __FILE__ ),
127+
'newspack-network-outgoing-post',
128+
plugins_url( '../../dist/outgoing-post.js', __FILE__ ),
130129
[],
131-
filemtime( NEWSPACK_NETWORK_PLUGIN_DIR . 'dist/distribute.js' ),
130+
filemtime( NEWSPACK_NETWORK_PLUGIN_DIR . 'dist/outgoing-post.js' ),
132131
true
133132
);
134133
wp_register_style(
135-
'newspack-network-distribute',
136-
plugins_url( '../../dist/distribute.css', __FILE__ ),
134+
'newspack-network-outgoing-post',
135+
plugins_url( '../../dist/outgoing-post.css', __FILE__ ),
137136
[],
138-
filemtime( NEWSPACK_NETWORK_PLUGIN_DIR . 'dist/distribute.css' ),
137+
filemtime( NEWSPACK_NETWORK_PLUGIN_DIR . 'dist/outgoing-post.css' ),
139138
);
140-
wp_style_add_data( 'newspack-network-distribute', 'rtl', 'replace' );
141-
wp_enqueue_style( 'newspack-network-distribute' );
139+
wp_style_add_data( 'newspack-network-outgoing-post', 'rtl', 'replace' );
140+
wp_enqueue_style( 'newspack-network-outgoing-post' );
142141

143142
wp_localize_script(
144-
'newspack-network-distribute',
145-
'newspack_network_distribute',
143+
'newspack-network-outgoing-post',
144+
'newspack_network_outgoing_post',
146145
[
147146
'network_sites' => Network::get_networked_urls(),
148147
'distributed_meta' => Outgoing_Post::DISTRIBUTED_POST_META,

src/content-distribution/content-distribution-panel/style.scss

+27
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,41 @@
1111
border: 0;
1212
}
1313

14+
.content-distribution-panel-header {
15+
> *:last-child,
16+
.components-base-control__field {
17+
margin: 0;
18+
}
19+
}
20+
1421
.content-distribution-panel-body {
1522
flex: 1 1 100%;
1623
overflow-y: auto;
1724
padding-top: 0;
1825

26+
.components-checkbox-control {
27+
padding: 12px 0;
28+
.components-base-control__field {
29+
margin-bottom: 0;
30+
}
31+
label {
32+
white-space: nowrap;
33+
overflow: hidden;
34+
text-overflow: ellipsis;
35+
}
36+
&:has( input:disabled ) {
37+
opacity: 0.5;
38+
}
39+
&:has( input[name="select-all"] ) label {
40+
font-weight: 600;
41+
}
42+
}
1943
}
2044

2145
.content-distribution-panel__button-column {
46+
p:first-child {
47+
margin-bottom: 0;
48+
}
2249
.components-button {
2350
justify-content: center;
2451
}

src/content-distribution/distribute/style.scss

-46
This file was deleted.

src/content-distribution/incoming-post/style.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
@include grey-out-inner;
6767
}
6868
}
69-
}
69+
}

src/content-distribution/distribute/index.js src/content-distribution/outgoing-post/index.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals newspack_network_distribute */
1+
/* globals newspack_network_outgoing_post */
22

33
/**
44
* WordPress dependencies.
@@ -7,21 +7,20 @@ import apiFetch from '@wordpress/api-fetch';
77
import { sprintf, __, _n } from '@wordpress/i18n';
88
import { useState, useEffect } from '@wordpress/element';
99
import { useSelect, useDispatch } from '@wordpress/data';
10-
import { PluginSidebar } from '@wordpress/editor';
11-
import { Panel, PanelBody, CheckboxControl, TextControl, Button } from '@wordpress/components';
10+
import { CheckboxControl, TextControl, Button } from '@wordpress/components';
1211
import { globe } from '@wordpress/icons';
1312
import { registerPlugin } from '@wordpress/plugins';
1413

1514
/**
1615
* Internal dependencies.
1716
*/
18-
import './style.scss';
17+
import ContentDistributionPanel from '../content-distribution-panel';
1918

20-
const networkSites = newspack_network_distribute.network_sites;
21-
const distributedMetaKey = newspack_network_distribute.distributed_meta;
22-
const postTypeLabel = newspack_network_distribute.post_type_label;
19+
const networkSites = newspack_network_outgoing_post.network_sites;
20+
const distributedMetaKey = newspack_network_outgoing_post.distributed_meta;
21+
const postTypeLabel = newspack_network_outgoing_post.post_type_label;
2322

24-
function Distribute() {
23+
function OutgoingPost() {
2524
const [ search, setSearch ] = useState( '' );
2625
const [ isDistributing, setIsDistributing ] = useState( false );
2726
const [ distribution, setDistribution ] = useState( [] );
@@ -124,14 +123,9 @@ function Distribute() {
124123
}
125124

126125
return (
127-
<PluginSidebar
128-
name="newspack-network-distribute"
129-
icon={ globe }
130-
title={ __( 'Distribute', 'newspack-network' ) }
131-
className="newspack-network-distribute"
132-
>
133-
<Panel>
134-
<PanelBody className="distribute-header">
126+
<ContentDistributionPanel
127+
header={ (
128+
<>
135129
{ ! distribution.length ? (
136130
<p>
137131
{ isUnpublished ? (
@@ -164,8 +158,10 @@ function Distribute() {
164158
onChange={ setSearch }
165159
/>
166160
) }
167-
</PanelBody>
168-
<PanelBody className="distribute-body">
161+
</>
162+
) }
163+
body={ (
164+
<>
169165
{ networkSites.length > 1 && selectableSites.length !== 0 && sites.length === networkSites.length && (
170166
<CheckboxControl
171167
name="select-all"
@@ -190,8 +186,10 @@ function Distribute() {
190186
} }
191187
/>
192188
) ) }
193-
</PanelBody>
194-
<PanelBody className="distribute-footer">
189+
</>
190+
) }
191+
buttons={ (
192+
<>
195193
{ siteSelection.length > 0 && (
196194
<p>
197195
{ sprintf(
@@ -232,13 +230,13 @@ function Distribute() {
232230
__( 'Distribute', 'newspack-network' )
233231
) }
234232
</Button>
235-
</PanelBody>
236-
</Panel>
237-
</PluginSidebar>
233+
</>
234+
) }
235+
/>
238236
);
239237
}
240238

241-
registerPlugin( 'newspack-network-distribute', {
242-
render: Distribute,
239+
registerPlugin( 'newspack-network-outgoing-post', {
240+
render: OutgoingPost,
243241
icon: globe,
244242
} );

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = getBaseWebpackConfig(
1111
{
1212
entry: {
1313
'distribute-panel': path.join( __dirname, 'src', 'content-distribution', 'content-distribution-panel' ),
14-
'distribute': path.join( __dirname, 'src', 'content-distribution', 'distribute' ), // TODO. Rename to outgoing-post
14+
'outgoing-post': path.join( __dirname, 'src', 'content-distribution', 'outgoing-post' ),
1515
'incoming-post': path.join( __dirname, 'src', 'content-distribution', 'incoming-post' ),
1616
},
1717
}

0 commit comments

Comments
 (0)