// @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; const [url, setUrl] = React.useState(customServerUrl); React.useEffect(() => { const timer = setTimeout(() => { Comments.setServerUrl(customServerEnabled ? url : undefined); if (url !== customServerUrl) { setCustomServerUrl(url); } }, DEBOUNCE_TEXT_INPUT_MS); return () => clearTimeout(timer); }, [url, customServerUrl, customServerEnabled, setCustomServerUrl]); return ( { if (e.target.checked) { setCustomServerEnabled(false); } }} /> { if (e.target.checked) { setCustomServerEnabled(true); } }} /> {customServerEnabled && (
setUrl(e.target.value)} />
)}
); } export default SettingCommentsServer;