Desktop: Fix comment-server set to null unintentionally

## Issue
6956 Desktop: something wrong with Custom Comment Server setting

## Notes
- Should be calling `Comments.setServerUrl` to ensure all private variables are updated.
- Skip the react-setting update if there is no change.
This commit is contained in:
infinite-persistence 2021-08-26 17:22:53 +08:00
parent 01f73c4861
commit 64323013cf
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -15,16 +15,18 @@ type Props = {
function SettingCommentsServer(props: Props) {
const { customServerEnabled, customServerUrl, setCustomServerEnabled, setCustomServerUrl } = props;
const [customUrl, setCustomUrl] = React.useState(customServerUrl);
const [url, setUrl] = React.useState(customServerUrl);
React.useEffect(() => {
const timer = setTimeout(() => {
setCustomServerUrl(customUrl);
Comments.url = customUrl;
Comments.setServerUrl(customServerEnabled ? url : undefined);
if (url !== customServerUrl) {
setCustomServerUrl(url);
}
}, DEBOUNCE_TEXT_INPUT_MS);
return () => clearTimeout(timer);
}, [customUrl, setCustomServerUrl]);
}, [url, customServerUrl, customServerEnabled, setCustomServerUrl]);
return (
<React.Fragment>
@ -57,8 +59,8 @@ function SettingCommentsServer(props: Props) {
<FormField
type="text"
placeholder="https://comment.mysite.com"
value={customUrl}
onChange={(e) => setCustomUrl(e.target.value)}
value={url}
onChange={(e) => setUrl(e.target.value)}
/>
</div>
)}