forked from BetterECNU/SharedCourses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
58 lines (51 loc) · 1.52 KB
/
Copy pathindex.tsx
File metadata and controls
58 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { forwardRef, useEffect, useState } from 'react';
import BrowserOnly from '@docusaurus/BrowserOnly';
import Giscus, { GiscusProps } from '@giscus/react';
import {
useThemeConfig,
useColorMode,
ThemeConfig
} from '@docusaurus/theme-common';
interface CustomThemeConfig extends ThemeConfig {
giscus: GiscusProps & { darkTheme: string };
}
export const Comment = forwardRef<HTMLDivElement>((_props, ref) => {
const { giscus } = useThemeConfig() as CustomThemeConfig;
const { colorMode } = useColorMode();
const { theme = 'light', darkTheme = 'dark_dimmed' } = giscus;
const giscusTheme = colorMode === 'dark' ? darkTheme : theme;
const [routeDidUpdate, setRouteDidUpdate] = useState(false);
useEffect(() => {
function eventHandler(e) {
setRouteDidUpdate(true);
}
window.emitter.on('onRouteDidUpdate', eventHandler);
return () => {
window.emitter.off('onRouteDidUpdate', eventHandler);
};
}, []);
if (!routeDidUpdate) {
return null;
}
return (
<BrowserOnly fallback={<div>Loading Comments...</div>}>
{() => (
<div ref={ref} id="comment" style={{ paddingTop: 50 }}>
<Giscus
id="comments"
mapping="title"
strict="1"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="bottom"
lang="zh-CN"
loading="lazy"
{...giscus}
theme={giscusTheme}
/>
</div>
)}
</BrowserOnly>
);
});
export default Comment;