Skip to content

Commit

Permalink
refactor: use foxact/use-abortable-effect
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 5, 2024
1 parent d2996f2 commit 8b9da00
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/entry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { useEffect } from 'foxact/use-abortable-effect';
import { Disqus } from './components/Disqus';
import { DisqusJSThread } from './components/Disscussion';
import { DisqusJSError } from './components/Error';
Expand All @@ -9,6 +9,7 @@ import { useMessage, useSetMessage } from './context/message';
import { checkDomainAccessiblity } from './lib/util';
import { useMode, useSetMode } from './context/mode';
import { useConfig } from './context/config';
import type { sign } from 'crypto';

export const DisqusJSEntry = () => {
const setMsg = useSetMessage();
Expand All @@ -18,9 +19,7 @@ export const DisqusJSEntry = () => {

const { shortname, identifier, url, title } = useConfig();

useEffect(() => {
let cancel = false;

useEffect(signal => {
if (mode === 'disqus' || mode === 'dsqjs') {
return;
}
Expand All @@ -30,18 +29,14 @@ export const DisqusJSEntry = () => {
Promise.all(
(['disqus.com', `${shortname}.disqus.com`]).map(checkDomainAccessiblity)
).then(() => {
if (!cancel) {
if (!signal.aborted) {
setMode('disqus');
}
}).catch(() => {
if (!cancel) {
if (!signal.aborted) {
setMode('dsqjs');
}
});

return () => {
cancel = true;
};
}, [mode, setMode, setMsg, shortname]);

const disqusJsHasError = useHasError();
Expand Down

0 comments on commit 8b9da00

Please sign in to comment.