forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
40 lines (33 loc) · 958 Bytes
/
index.tsx
File metadata and controls
40 lines (33 loc) · 958 Bytes
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
import { createElement, SFC, useState, useEffect } from 'react'
import { useOvermind } from '../../overmind'
import GuideToc from '../GuideToc'
import Doc from '../Doc'
import * as styles from './styles'
import { compile, getGithubBaseUrl } from '../../utils'
function getGithubUrl(guide) {
return (
getGithubBaseUrl() + '/guides/' + guide.type + '/' + guide.title + '.md'
)
}
const Guide: SFC = () => {
const { state } = useOvermind()
const [content, setContent] = useState(null)
useEffect(() => {
import('../../../guides/' +
state.currentGuide.type +
'/' +
state.currentGuide.title +
'.md').then((module) => setContent(module))
}, [])
if (!content) {
return null
}
const compiled = compile(content)
return (
<div className={styles.wrapper}>
<Doc url={getGithubUrl(state.currentGuide)}>{compiled.tree}</Doc>
<GuideToc toc={compiled.toc} />
</div>
)
}
export default Guide