forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuide.js
More file actions
47 lines (44 loc) · 1.32 KB
/
Guide.js
File metadata and controls
47 lines (44 loc) · 1.32 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
import React from "react";
import PropTypes from "prop-types";
import { Redirect, Route } from "react-router-dom";
import { Block } from "jsxstyle";
import ScrollToDoc from "./ScrollToDoc.js";
import MarkdownViewer from "./MarkdownViewer.js";
// almost identical to `API`, but I'm lazy rn
export default function Guide({ match, data }) {
const {
params: { mod, header: headerParam, environment }
} = match;
const doc = data.guides.find(doc => mod === doc.title.slug);
const header =
doc && headerParam ? doc.headers.find(h => h.slug === headerParam) : null;
return !doc ? (
<Redirect to={`/${environment}`} />
) : (
<Block className="api-doc-wrapper" fontSize="80%">
<Block className="api-doc">
<ScrollToDoc doc={doc} header={header} />
<MarkdownViewer html={doc.markup} />
</Block>
<Route
path={`${match.path}/:header`}
render={({
match: {
params: { header: slug }
}
}) => {
const header = doc.headers.find(h => h.slug === slug);
return header ? (
<ScrollToDoc doc={doc} header={header} />
) : (
<Redirect to={`/${environment}/guides/${mod}`} />
);
}}
/>
</Block>
);
}
Guide.propTypes = {
match: PropTypes.object,
data: PropTypes.object
};