Skip to content

Commit 41b2fe9

Browse files
committed
chore: make eslint happier
1 parent 9084188 commit 41b2fe9

File tree

1 file changed

+55
-41
lines changed

1 file changed

+55
-41
lines changed

src/components/Disqus.tsx

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,55 @@ declare global {
2020
}
2121
}
2222

23+
function loadDisqusInstance(config: DisqusConfig, onReady: () => void) {
24+
if (typeof window === 'undefined') {
25+
return;
26+
}
27+
28+
if (window.DISQUS && document.getElementById(EMBED_SCRIPT_ID)) {
29+
window.DISQUS.reset({
30+
reload: true,
31+
// eslint-disable-next-line object-shorthand -- Disqus uses this
32+
config: function (this: any) {
33+
if (config.identifier) {
34+
this.page.identifier = config.identifier;
35+
}
36+
if (config.url) {
37+
this.page.url = config.url;
38+
}
39+
if (config.title) {
40+
this.page.title = config.title;
41+
}
42+
this.callbacks.onReady = [
43+
onReady
44+
];
45+
}
46+
});
47+
} else {
48+
window.disqus_config = function (this: any) {
49+
if (config.identifier) {
50+
this.page.identifier = config.identifier;
51+
}
52+
if (config.identifier) {
53+
this.page.url = config.identifier;
54+
}
55+
if (config.identifier) {
56+
this.page.title = config.identifier;
57+
}
58+
this.callbacks.onReady = [
59+
onReady
60+
];
61+
};
62+
window.disqus_shortname = config.shortname;
63+
64+
const scriptEl = document.createElement('script');
65+
scriptEl.id = EMBED_SCRIPT_ID;
66+
scriptEl.src = `https://${config.shortname}.disqus.com/embed.js`;
67+
scriptEl.async = true;
68+
document.head.appendChild(scriptEl);
69+
}
70+
};
71+
2372
export const Disqus = memo(({
2473
shortname,
2574
identifier,
@@ -68,47 +117,12 @@ export const Disqus = memo(({
68117
clearDisqusInstance();
69118
}
70119

71-
if (window.DISQUS && document.getElementById(EMBED_SCRIPT_ID)) {
72-
window.DISQUS.reset({
73-
reload: true,
74-
config(this: any) {
75-
if (identifier) {
76-
this.page.identifier = identifier;
77-
}
78-
if (url) {
79-
this.page.url = url;
80-
}
81-
if (title) {
82-
this.page.title = title;
83-
}
84-
this.callbacks.onReady = [
85-
() => setLoaded(true)
86-
];
87-
}
88-
});
89-
} else {
90-
window.disqus_config = function (this: any) {
91-
if (identifier) {
92-
this.page.identifier = identifier;
93-
}
94-
if (url) {
95-
this.page.url = url;
96-
}
97-
if (title) {
98-
this.page.title = title;
99-
}
100-
this.callbacks.onReady = [
101-
() => setLoaded(true)
102-
];
103-
};
104-
window.disqus_shortname = shortname;
105-
106-
const scriptEl = document.createElement('script');
107-
scriptEl.id = EMBED_SCRIPT_ID;
108-
scriptEl.src = `https://${shortname}.disqus.com/embed.js`;
109-
scriptEl.async = true;
110-
document.head.appendChild(scriptEl);
111-
}
120+
loadDisqusInstance({
121+
shortname,
122+
identifier,
123+
url,
124+
title
125+
}, () => setLoaded(true));
112126

113127
return clearDisqusInstance;
114128
}, [shortname, identifier, url, title]);

0 commit comments

Comments
 (0)