-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
prepublish.js
153 lines (142 loc) · 3.74 KB
/
prepublish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* External dependencies
*/
import { get } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Icon, PanelBody } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { wordpress } from '@wordpress/icons';
import { filterURLForDisplay } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
import PostVisibility from '../post-visibility';
import PostVisibilityLabel from '../post-visibility/label';
import PostSchedule from '../post-schedule';
import PostScheduleLabel from '../post-schedule/label';
import MaybeTagsPanel from './maybe-tags-panel';
import MaybePostFormatPanel from './maybe-post-format-panel';
import { store as editorStore } from '../../store';
function PostPublishPanelPrepublish( { children } ) {
const {
isBeingScheduled,
isRequestingSiteIcon,
hasPublishAction,
siteIconUrl,
siteTitle,
siteHome,
} = useSelect( ( select ) => {
const { isResolving } = select( 'core/data' );
const { getCurrentPost, isEditedPostBeingScheduled } = select(
editorStore
);
const { getEntityRecord } = select( coreStore );
const siteData =
getEntityRecord( 'root', '__unstableBase', undefined ) || {};
return {
hasPublishAction: get(
getCurrentPost(),
[ '_links', 'wp:action-publish' ],
false
),
isBeingScheduled: isEditedPostBeingScheduled(),
isRequestingSiteIcon: isResolving( 'core', 'getEntityRecord', [
'root',
'__unstableBase',
undefined,
] ),
siteIconUrl: siteData.site_icon_url,
siteTitle: siteData.name,
siteHome: siteData.home && filterURLForDisplay( siteData.home ),
};
}, [] );
let siteIcon = (
<Icon className="components-site-icon" size="36px" icon={ wordpress } />
);
if ( siteIconUrl ) {
siteIcon = (
<img
alt={ __( 'Site Icon' ) }
className="components-site-icon"
src={ siteIconUrl }
/>
);
}
if ( isRequestingSiteIcon ) {
siteIcon = null;
}
let prePublishTitle, prePublishBodyText;
if ( ! hasPublishAction ) {
prePublishTitle = __( 'Are you ready to submit for review?' );
prePublishBodyText = __(
'When you’re ready, submit your work for review, and an Editor will be able to approve it for you.'
);
} else if ( isBeingScheduled ) {
prePublishTitle = __( 'Are you ready to schedule?' );
prePublishBodyText = __(
'Your work will be published at the specified date and time.'
);
} else {
prePublishTitle = __( 'Are you ready to publish?' );
prePublishBodyText = __(
'Double-check your settings before publishing.'
);
}
return (
<div className="editor-post-publish-panel__prepublish">
<div>
<strong>{ prePublishTitle }</strong>
</div>
<p>{ prePublishBodyText }</p>
<div className="components-site-card">
{ siteIcon }
<div className="components-site-info">
<span className="components-site-name">
{ siteTitle || __( '(Untitled)' ) }
</span>
<span className="components-site-home">{ siteHome }</span>
</div>
</div>
{ hasPublishAction && (
<>
<PanelBody
initialOpen={ false }
title={ [
__( 'Visibility:' ),
<span
className="editor-post-publish-panel__link"
key="label"
>
<PostVisibilityLabel />
</span>,
] }
>
<PostVisibility />
</PanelBody>
<PanelBody
initialOpen={ false }
title={ [
__( 'Publish:' ),
<span
className="editor-post-publish-panel__link"
key="label"
>
<PostScheduleLabel />
</span>,
] }
>
<PostSchedule />
</PanelBody>
</>
) }
<MaybePostFormatPanel />
<MaybeTagsPanel />
{ children }
</div>
);
}
export default PostPublishPanelPrepublish;