Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | import { getRedirectUrl } from '@automattic/jetpack-components';
import { ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Component } from 'react';
import { FormFieldset, FormLabel } from 'components/forms';
import { withModuleSettingsFormHelpers } from 'components/module-settings/with-module-settings-form-helpers';
import { ModuleToggle } from 'components/module-toggle';
import SettingsCard from 'components/settings-card';
import SettingsGroup from 'components/settings-group';
import SupportInfo from 'components/support-info';
import TextInput from 'components/text-input';
import './style.scss';
class CommentsComponent extends Component {
/**
* If markdown module is inactive and this is toggling markdown for comments on, activate module.
* If markdown for posts is off and this is toggling markdown for comments off, deactivate module.
*
* @param {string} module - the module slug.
* @return {*} the updated value
*/
updateFormStateByMarkdown = module => {
if ( this.props.getSettingCurrentValue( 'wpcom_publish_posts_with_markdown', module ) ) {
return this.props.updateFormStateModuleOption(
module,
'wpcom_publish_comments_with_markdown'
);
}
return this.props.updateFormStateModuleOption(
module,
'wpcom_publish_comments_with_markdown',
true
);
};
handleMarkdownCommentsToggle = () => {
this.props.updateFormStateModuleOption( 'markdown', 'wpcom_publish_comments_with_markdown' );
};
handleImagesToggle = () => {
this.props.updateFormStateModuleOption( 'comments', 'jetpack_comments_images' );
};
handleEmbedsToggle = () => {
this.props.updateFormStateModuleOption( 'comments', 'jetpack_comments_embeds' );
};
render() {
const foundComments = this.props.isModuleFound( 'comments' ),
foundGravatar = this.props.isModuleFound( 'gravatar-hovercards' ),
foundMarkdown = this.props.isModuleFound( 'markdown' ),
foundCommentLikes = this.props.isModuleFound( 'comment-likes' );
if ( ! foundComments && ! foundGravatar && ! foundMarkdown && ! foundCommentLikes ) {
return null;
}
const { isUnavailableInOfflineMode: isUnavailableInOfflineMode, getOptionValue } = this.props;
const comments = this.props.getModule( 'comments' ),
isCommentsActive = this.props.getOptionValue( 'comments' ),
commentsUnavailableInOfflineMode = this.props.isUnavailableInOfflineMode( 'comments' ),
gravatar = this.props.getModule( 'gravatar-hovercards' ),
markdown = this.props.getModule( 'markdown' ),
commentLikesUnavailable = isUnavailableInOfflineMode( 'comment-likes' ),
commentLikesActive = getOptionValue( 'comment-likes' );
return (
<SettingsCard
{ ...this.props }
header={ __( 'Comments', 'jetpack' ) }
module="comments"
saveDisabled={ this.props.isSavingAnyOption( [
'highlander_comment_form_prompt',
'jetpack_comments_images',
'jetpack_comments_embeds',
] ) }
>
{ foundComments && (
<SettingsGroup
hasChild
disableInOfflineMode
module={ comments }
support={ {
text: __(
'Replaces the standard WordPress comment form with a new comment system that includes social media login options.',
'jetpack'
),
link: getRedirectUrl( 'jetpack-support-comments' ),
wpcomLink: 'https://wordpress.com/support/comments/',
} }
>
<ModuleToggle
slug="comments"
compact
disabled={
commentsUnavailableInOfflineMode || this.props.isSavingAnyOption( 'comments' )
}
activated={ this.props.getOptionValue( 'comments' ) }
toggleModule={ this.props.toggleModuleNow }
>
<span className="jp-form-toggle-explanation">{ comments.description }</span>
</ModuleToggle>
{ this.props.hasBlockEditor && (
<>
<FormFieldset>
<ToggleControl
checked={
!! this.props.getOptionValue( 'jetpack_comments_images', 'comments' )
}
disabled={
! isCommentsActive ||
commentsUnavailableInOfflineMode ||
this.props.isSavingAnyOption( [ 'comments', 'jetpack_comments_images' ] )
}
onChange={ this.handleImagesToggle }
label={
<span className="jp-form-toggle-explanation">
{ __( 'Allow images from links.', 'jetpack' ) }
</span>
}
__nextHasNoMarginBottom={ true }
/>
</FormFieldset>
<FormFieldset>
<ToggleControl
checked={
!! this.props.getOptionValue( 'jetpack_comments_embeds', 'comments' )
}
disabled={
! isCommentsActive ||
commentsUnavailableInOfflineMode ||
this.props.isSavingAnyOption( [ 'comments', 'jetpack_comments_embeds' ] )
}
onChange={ this.handleEmbedsToggle }
label={
<span className="jp-form-toggle-explanation">
{ __( 'Allow embeds from YouTube, X, and other services.', 'jetpack' ) }
</span>
}
__nextHasNoMarginBottom={ true }
/>
</FormFieldset>
</>
) }
<FormFieldset>
<FormLabel>
<span className="jp-form-label-wide">
{ __( 'Comment form introduction', 'jetpack' ) }
</span>
<TextInput
name={ 'highlander_comment_form_prompt' }
value={ this.props.getOptionValue( 'highlander_comment_form_prompt' ) }
disabled={
! isCommentsActive ||
commentsUnavailableInOfflineMode ||
this.props.isSavingAnyOption( 'highlander_comment_form_prompt' )
}
onChange={ this.props.onOptionChange }
/>
</FormLabel>
<span className="jp-form-setting-explanation">
{ __( 'A few catchy words to motivate your visitors to comment.', 'jetpack' ) }
</span>
</FormFieldset>
</SettingsGroup>
) }
{ ( foundGravatar || foundMarkdown || foundCommentLikes ) && (
<SettingsGroup>
{ foundGravatar && (
<div className="jp-toggle-set">
<FormFieldset>
<ModuleToggle
slug="gravatar-hovercards"
compact
disabled={ this.props.isSavingAnyOption( 'gravatar-hovercards' ) }
activated={ this.props.getOptionValue( 'gravatar-hovercards' ) }
toggleModule={ this.props.toggleModuleNow }
>
<span className="jp-form-toggle-explanation">{ gravatar.description }</span>
</ModuleToggle>
</FormFieldset>
<SupportInfo
text={ __( 'Show Gravatar hovercards alongside comments.', 'jetpack' ) }
link={ gravatar.learn_more_button }
privacyLink={ gravatar.learn_more_button + '#privacy' }
wpcomLink="https://wordpress.com/support/gravatars/"
/>
</div>
) }
{ foundMarkdown && (
<div className="jp-toggle-set">
<FormFieldset>
<ToggleControl
checked={
!! this.props.getOptionValue(
'wpcom_publish_comments_with_markdown',
'markdown'
)
}
disabled={
this.props.isSavingAnyOption( [ 'markdown' ] ) ||
'inactive' === this.props.getModuleOverride( 'markdown' )
}
onChange={ this.handleMarkdownCommentsToggle }
label={
<span className="jp-form-toggle-explanation">
{ __( 'Enable Markdown use for comments.', 'jetpack' ) }
</span>
}
__nextHasNoMarginBottom={ true }
/>
</FormFieldset>
<SupportInfo
text={ __( 'Allow readers to use markdown in comments.', 'jetpack' ) }
link={ markdown.learn_more_button }
privacyLink={ markdown.learn_more_button + '#privacy' }
wpcomLink="https://wordpress.com/support/wordpress-editor/blocks/markdown-block/"
/>
</div>
) }
{ foundCommentLikes && (
<div className="jp-toggle-set">
<FormFieldset>
<ModuleToggle
slug="comment-likes"
compact
disabled={
commentLikesUnavailable || this.props.isSavingAnyOption( 'comment-likes' )
}
activated={ commentLikesActive }
toggleModule={ this.props.toggleModuleNow }
>
<span className="jp-form-toggle-explanation">
{ __( 'Enable comment Likes.', 'jetpack' ) }
</span>
</ModuleToggle>
</FormFieldset>
<SupportInfo
text={ __( 'Allow readers to like individual comments.', 'jetpack' ) }
link={ getRedirectUrl( 'jetpack-support-comment-likes' ) }
privacyLink={ getRedirectUrl( 'jetpack-support-comment-likes', {
anchor: 'privacy',
} ) }
wpcomLink="https://wordpress.com/support/comment-likes/"
/>
</div>
) }
</SettingsGroup>
) }
</SettingsCard>
);
}
}
export const Comments = withModuleSettingsFormHelpers( CommentsComponent );
|