-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathFeatureRequestsPage.tsx
More file actions
68 lines (60 loc) · 1.7 KB
/
FeatureRequestsPage.tsx
File metadata and controls
68 lines (60 loc) · 1.7 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
59
60
61
62
63
64
65
66
67
68
import React, {type ReactNode, useEffect, useState} from 'react';
import clsx from 'clsx';
import {useColorMode} from '@docusaurus/theme-common';
import Layout from '@theme/Layout';
import cannyScript from './cannyScript';
import styles from './styles.module.css';
// const BOARD_TOKEN = '054e0e53-d951-b14c-7e74-9eb8f9ed2f91';
const BOARD_TOKEN = 'dc17efce-4d94-9338-127d-509732d11df3';
// TODO useColorMode() hook is not reliable on first call
function useIsColorModeReliable() {
const [isColorModeReliable, setIsColorModeReliable] = useState(false);
useEffect(() => {
setIsColorModeReliable(true);
}, []);
return isColorModeReliable;
}
function useCannyTheme() {
const {colorMode} = useColorMode();
const isColorModeReliable = useIsColorModeReliable();
if (!isColorModeReliable) {
return null;
}
return colorMode === 'light' ? 'light' : 'dark';
}
function CannyWidget({basePath}: {basePath: string}) {
useEffect(() => {
cannyScript();
}, []);
const theme = useCannyTheme();
useEffect(() => {
if (!theme) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const {Canny} = window as any;
Canny('render', {
boardToken: BOARD_TOKEN,
basePath,
theme,
});
}, [basePath, theme]);
return (
<main
key={theme} // widget needs a full reset: unable to update the theme
className={clsx('container', 'margin-vert--lg', styles.main)}
data-canny
/>
);
}
export default function FeatureRequests({
basePath,
}: {
basePath: string;
}): ReactNode {
return (
<Layout title="Feedback" description="Docusaurus 2 Feature Requests page">
<CannyWidget basePath={basePath} />
</Layout>
);
}