Skip to content

Commit f160936

Browse files
committed
fix: post update component refreshing
1 parent 54fe545 commit f160936

12 files changed

Lines changed: 980 additions & 925 deletions

File tree

.distignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ composer.lock
2323
key.enc
2424
package-lock.json
2525
vue
26-
/src // Only the root src directory to avoid dependency directories being ignored
26+
/src
2727
.github
2828
.vscode
2929
.wordpress-org
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-notices', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '53235e9b63e3791f4fc9');
1+
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-notices', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '123dd2715f24fa986db7');

assets/js/react/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 79 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
PluginPostPublishPanel,
1212
PluginSidebar,
1313
PluginSidebarMoreMenuItem,
14-
store as editorStore
14+
store as editorStore,
1515
} from '@wordpress/editor';
1616

1717
import { useEffect } from '@wordpress/element';
@@ -36,121 +36,137 @@ const icon = (
3636
/>
3737
);
3838

39-
const isPro = Number( ropApiSettings.license_type ) > 0;
39+
const isPro = Number(ropApiSettings.license_type) > 0;
4040

4141
const render = () => {
42-
const postType = useSelect( select => select( editorStore ).getCurrentPostType(), [] );
43-
const postStatus = useSelect( select => select( editorStore ).getCurrentPostAttribute( 'status' ), [] );
42+
const postType = useSelect(
43+
(select) => select(editorStore).getCurrentPostType(),
44+
[]
45+
);
46+
const postStatus = useSelect(
47+
(select) => select(editorStore).getCurrentPostAttribute('status'),
48+
[]
49+
);
4450

45-
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
51+
const [ meta, setMeta ] = useEntityProp('postType', postType, 'meta');
4652

47-
const updateMetaValue = ( keyOrObject, newValue ) => {
48-
if ( typeof keyOrObject === 'object' && keyOrObject !== null ) {
49-
setMeta( { ...meta, ...keyOrObject } );
53+
const updateMetaValue = (keyOrObject, newValue) => {
54+
if (typeof keyOrObject === 'object' && keyOrObject !== null) {
55+
setMeta({ ...meta, ...keyOrObject });
5056
} else {
51-
setMeta( { ...meta, [keyOrObject]: newValue } );
57+
setMeta({ ...meta, [keyOrObject]: newValue });
5258
}
5359
};
5460

55-
useEffect( () => {
56-
if ( meta.rop_publish_now ) {
57-
updateMetaValue( 'rop_publish_now', 'yes' );
61+
useEffect(() => {
62+
if (meta.rop_publish_now) {
63+
updateMetaValue('rop_publish_now', 'yes');
5864
}
59-
}, [] );
65+
}, []);
6066

6167
return (
6268
<>
63-
<PluginSidebarMoreMenuItem
64-
target="rop-sidebar"
65-
icon={ icon }
66-
>
67-
{ ropApiSettings.labels.general.plugin_name }
69+
<PluginSidebarMoreMenuItem target="rop-sidebar" icon={icon}>
70+
{ropApiSettings.labels.general.plugin_name}
6871
</PluginSidebarMoreMenuItem>
6972

7073
<PluginSidebar
7174
name="rop-sidebar"
72-
icon={ icon }
73-
title={ ropApiSettings.labels.general.plugin_name }
75+
icon={icon}
76+
title={ropApiSettings.labels.general.plugin_name}
7477
className="revive-social-sidebar"
7578
>
76-
{ Boolean( ropApiSettings.publish_now.instant_share_enabled ) && (
79+
{Boolean(ropApiSettings.publish_now.instant_share_enabled) && (
7780
<>
78-
<PanelBody title={ ropApiSettings.labels.publish_now.instant_sharing }>
81+
<PanelBody
82+
title={
83+
ropApiSettings.labels.publish_now
84+
.instant_sharing
85+
}
86+
>
7987
<InstantSharing
8088
screen="pre-publish"
81-
meta={ meta }
82-
updateMetaValue={ updateMetaValue }
83-
postStatus={ postStatus }
84-
publishStatus={ meta.rop_publish_now_status }
89+
meta={meta}
90+
updateMetaValue={updateMetaValue}
91+
postStatus={postStatus}
92+
publishStatus={meta.rop_publish_now_status}
8593
/>
8694
</PanelBody>
8795

88-
{ postStatus === 'publish' && (
89-
<PanelBody title={ ropApiSettings.labels.publish_now.manual_sharing }>
96+
{postStatus === 'publish' && (
97+
<PanelBody
98+
title={
99+
ropApiSettings.labels.publish_now
100+
.manual_sharing
101+
}
102+
>
90103
<ManualSharing />
91104
</PanelBody>
92-
) }
105+
)}
93106
</>
94-
) }
95-
96-
{ ( isPro && Boolean( ropApiSettings.custom_messages ) ) && (
97-
<Variations
98-
meta={ meta }
99-
updateMetaValue={ updateMetaValue }
100-
/>
101-
) }
102-
103-
{ ! isPro && (
104-
<Upsell />
105-
) }
107+
)}
108+
109+
{isPro && Boolean(ropApiSettings.custom_messages) && (
110+
<Variations meta={meta} updateMetaValue={updateMetaValue} />
111+
)}
112+
113+
{!isPro && <Upsell />}
106114
</PluginSidebar>
107115

108-
{ Boolean( ropApiSettings.publish_now.instant_share_enabled ) && (
116+
{Boolean(ropApiSettings.publish_now.instant_share_enabled) && (
109117
<>
110118
<PluginPrePublishPanel
111-
title={ ropApiSettings.labels.publish_now.instant_sharing }
112-
isInitialOpen={ true }
113-
icon={ icon }
119+
title={
120+
ropApiSettings.labels.publish_now.instant_sharing
121+
}
122+
isInitialOpen={true}
123+
icon={icon}
114124
>
115125
<InstantSharing
116126
screen="pre-publish"
117-
meta={ meta }
118-
updateMetaValue={ updateMetaValue }
119-
postStatus={ postStatus }
120-
publishStatus={ meta.rop_publish_now_status }
127+
meta={meta}
128+
updateMetaValue={updateMetaValue}
129+
postStatus={postStatus}
130+
publishStatus={meta.rop_publish_now_status}
121131
/>
122132
</PluginPrePublishPanel>
123133

124-
{ postStatus === 'publish' && (
134+
{postStatus === 'publish' && (
125135
<>
126136
<PluginPostPublishPanel
127-
icon={ icon }
128-
isInitialOpen={ true }
137+
icon={icon}
138+
isInitialOpen={true}
129139
>
130140
<InstantSharing
131141
screen="post-publish"
132-
meta={ meta }
133-
updateMetaValue={ updateMetaValue }
134-
postStatus={ postStatus }
135-
publishStatus={ meta.rop_publish_now_status }
142+
meta={meta}
143+
updateMetaValue={updateMetaValue}
144+
postStatus={postStatus}
145+
publishStatus={meta.rop_publish_now_status}
136146
/>
137147
</PluginPostPublishPanel>
138148

139149
<PluginPostPublishPanel
140-
title={ ropApiSettings.labels.publish_now.manual_sharing }
141-
icon={ icon }
142-
isInitialOpen={ true }
150+
title={
151+
ropApiSettings.labels.publish_now
152+
.manual_sharing
153+
}
154+
icon={icon}
155+
isInitialOpen={true}
143156
>
144157
<ManualSharing />
145158
</PluginPostPublishPanel>
146159
</>
147-
) }
160+
)}
148161
</>
149-
) }
162+
)}
150163
</>
151164
);
152165
};
153166

154-
if ( Boolean( ropApiSettings.publish_now.instant_share_enabled ) || ( isPro && Boolean( ropApiSettings.custom_messages ) ) ) {
155-
registerPlugin( 'revive-social', { render } );
167+
if (
168+
Boolean(ropApiSettings.publish_now.instant_share_enabled) ||
169+
(isPro && Boolean(ropApiSettings.custom_messages))
170+
) {
171+
registerPlugin('revive-social', { render });
156172
}

0 commit comments

Comments
 (0)