ff9ca662f2
## Issue > 5459 Add setting for changing your comment server. Visible on desktop (and possibly defaulting to Odysee URL), hidden on odysee. ## Comments Not sure how this would actually work properly without the user recompiling the app to handle server differences. For example, even when we use our own server but switch between v1 and v2, some code changes are need to handle the differences. At that point, it seems easier for the user to just change the .env file? Anyway... ## Changes - Added Desktop-only options to define custom server. [Settings > Advanced Settings > "Comment server" section].
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
// @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 [customUrl, setCustomUrl] = React.useState(customServerUrl);
|
|
|
|
React.useEffect(() => {
|
|
const timer = setTimeout(() => {
|
|
setCustomServerUrl(customUrl);
|
|
Comments.url = customUrl;
|
|
}, DEBOUNCE_TEXT_INPUT_MS);
|
|
|
|
return () => clearTimeout(timer);
|
|
}, [customUrl, setCustomServerUrl]);
|
|
|
|
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"
|
|
value={customUrl}
|
|
onChange={(e) => setCustomUrl(e.target.value)}
|
|
/>
|
|
</div>
|
|
)}
|
|
</fieldset-section>
|
|
</React.Fragment>
|
|
);
|
|
}
|
|
|
|
export default SettingCommentsServer;
|