2021-07-25 14:52:45 +02:00
|
|
|
// @flow
|
|
|
|
import { COMMENT_SERVER_NAME } from 'config';
|
|
|
|
import React from 'react';
|
|
|
|
import Comments from 'comments';
|
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
|
|
|
|
const DEBOUNCE_TEXT_INPUT_MS = 500;
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
customServerEnabled: boolean,
|
|
|
|
customServerUrl: string,
|
|
|
|
setCustomServerEnabled: (boolean) => void,
|
|
|
|
setCustomServerUrl: (string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
function SettingCommentsServer(props: Props) {
|
|
|
|
const { customServerEnabled, customServerUrl, setCustomServerEnabled, setCustomServerUrl } = props;
|
2021-08-26 11:22:53 +02:00
|
|
|
const [url, setUrl] = React.useState(customServerUrl);
|
2021-07-25 14:52:45 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const timer = setTimeout(() => {
|
2021-08-26 11:22:53 +02:00
|
|
|
Comments.setServerUrl(customServerEnabled ? url : undefined);
|
|
|
|
if (url !== customServerUrl) {
|
|
|
|
setCustomServerUrl(url);
|
|
|
|
}
|
2021-07-25 14:52:45 +02:00
|
|
|
}, DEBOUNCE_TEXT_INPUT_MS);
|
|
|
|
|
|
|
|
return () => clearTimeout(timer);
|
2021-08-26 11:22:53 +02:00
|
|
|
}, [url, customServerUrl, customServerEnabled, setCustomServerUrl]);
|
2021-07-25 14:52:45 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<fieldset-section>
|
|
|
|
<FormField
|
|
|
|
type="radio"
|
|
|
|
name="use_default_comments_server"
|
|
|
|
label={__('Default comments server (%name%)', { name: COMMENT_SERVER_NAME })}
|
|
|
|
checked={!customServerEnabled}
|
|
|
|
onChange={(e) => {
|
|
|
|
if (e.target.checked) {
|
|
|
|
setCustomServerEnabled(false);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
type="radio"
|
|
|
|
name="use_custom_comments_server"
|
|
|
|
label={__('Custom comments server')}
|
|
|
|
checked={customServerEnabled}
|
|
|
|
onChange={(e) => {
|
|
|
|
if (e.target.checked) {
|
|
|
|
setCustomServerEnabled(true);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{customServerEnabled && (
|
|
|
|
<div className="section__body">
|
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
placeholder="https://comment.mysite.com"
|
2021-08-26 11:22:53 +02:00
|
|
|
value={url}
|
|
|
|
onChange={(e) => setUrl(e.target.value)}
|
2021-07-25 14:52:45 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</fieldset-section>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingCommentsServer;
|