-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.tsx
97 lines (87 loc) · 2.64 KB
/
index.tsx
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { css } from "@emotion/react";
import { useState } from "react";
import { apiReadmeShowPath } from "../../../lib/qiita-cli-url";
import { HeaderIndex } from "../../components/Header";
import { useHotReloadEffect } from "../../components/HotReloadRoot";
import { SidebarContents } from "../../components/SidebarContents";
import { breakpoint, viewport } from "../../lib/mixins";
import { Colors, Typography, getSpace } from "../../lib/variables";
import { useWindowSize } from "../../lib/window-size";
import { Contents } from "../../templates/Contents";
import { Main } from "../../templates/Main";
import { Sidebar } from "../../templates/Sidebar";
export const ItemsIndex = () => {
const [isStateOpen, setIsStateOpen] = useState(false);
const handleMobileOpen = () => {
setIsStateOpen(true);
};
const handleMobileClose = () => {
setIsStateOpen(false);
};
const { currentWidth } = useWindowSize();
const mobileSize = currentWidth <= breakpoint.S;
const [readme, setReadme] = useState<{
renderedBody: string;
} | null>(null);
const [error, setError] = useState<null | string>(null);
useHotReloadEffect(() => {
const fetchURL = apiReadmeShowPath();
fetch(fetchURL).then((response) => {
if (!response.ok) {
if (response.status === 404) {
setError("ファイルが見つかりません");
} else {
setError("不明なエラーが発生しました");
}
} else {
response.json().then((data) => {
setReadme(data);
});
}
});
}, []);
return (
<Main>
<Sidebar>
<SidebarContents
isStateOpen={isStateOpen}
handleMobileClose={handleMobileClose}
/>
</Sidebar>
<Contents>
{mobileSize && <HeaderIndex handleMobileOpen={handleMobileOpen} />}
{readme ? (
<div css={contentsWrapperStyle}>
<div css={contentsContainerStyle}>
<div className="it-MdContent">
<div
dangerouslySetInnerHTML={{ __html: readme.renderedBody }}
/>
</div>
</div>
</div>
) : error ? (
<p css={errorMessageStyle}>{error}</p>
) : null}
</Contents>
</Main>
);
};
const contentsWrapperStyle = css({
margin: `${getSpace(2)}px ${getSpace(2)}px 0`,
...viewport.S({
margin: 0,
}),
});
const contentsContainerStyle = css({
backgroundColor: Colors.gray0,
borderRadius: 8,
maxWidth: 820,
margin: "0 auto",
padding: getSpace(3),
});
const errorMessageStyle = css({
fontSize: Typography.subhead2,
padding: getSpace(2),
textAlign: "center",
});