-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.tsx
More file actions
53 lines (41 loc) · 1.34 KB
/
index.tsx
File metadata and controls
53 lines (41 loc) · 1.34 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
import { WikiNode } from 'mobx-lark';
import { observer } from 'mobx-react';
import { GetStaticProps } from 'next';
import { FC, useContext } from 'react';
import { Container } from 'react-bootstrap';
import { treeFrom } from 'web-utility';
import { PageHead } from '../../components/Layout/PageHead';
import { I18nContext } from '../../models/Translation';
import { wikiStore } from '../../models/Wiki';
import { lark } from '../api/Lark/core';
export const getStaticProps: GetStaticProps = async () => {
await lark.getAccessToken();
const nodes = await wikiStore.getAll();
return { props: { nodes } };
};
interface XWikiNode extends WikiNode {
// eslint-disable-next-line no-restricted-syntax
children?: XWikiNode[];
}
const renderTree = (children?: XWikiNode[]) =>
children && (
<ol>
{children.map(({ node_token, title, children }) => (
<li key={node_token}>
<a href={`/wiki/${node_token}`}>{title}</a>
{renderTree(children)}
</li>
))}
</ol>
);
const WikiIndexPage: FC<{ nodes: XWikiNode[] }> = observer(({ nodes }) => {
const { t } = useContext(I18nContext);
return (
<Container>
<PageHead title={t('wiki')} />
<h1>{t('wiki')}</h1>
{renderTree(treeFrom(nodes, 'node_token', 'parent_node_token', 'children'))}
</Container>
);
});
export default WikiIndexPage;