forked from railwayapp/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPage.tsx
More file actions
69 lines (58 loc) · 1.76 KB
/
Copy pathPage.tsx
File metadata and controls
69 lines (58 loc) · 1.76 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
69
import Fuse from "fuse.js";
import { useRouter } from "next/router";
import React, { useEffect, useMemo } from "react";
import tinykeys from "tinykeys";
import "twin.macro";
import { Footer } from "../components/Footer";
import { Modal } from "../components/Modal";
import { MobileNav, Nav } from "../components/Nav";
import { SearchModal } from "../components/Search";
import { Props as SEOProps, SEO } from "../components/SEO";
import { Sidebar } from "../components/Sidebar";
import { sidebarContent } from "../data/sidebar";
import { useStore } from "../store";
export interface Props {
seo?: SEOProps;
}
export const Page: React.FC<Props> = props => {
const { isSearchOpen, setIsSearchOpen } = useStore();
useEffect(() => {
const unsubscribe = tinykeys(window, {
"$mod+K": e => {
e.preventDefault();
setIsSearchOpen(!isSearchOpen);
},
});
return () => unsubscribe();
}, [isSearchOpen]);
const fuse = useMemo(() => {
const pages = sidebarContent.map(section => section.pages).flat();
const fuse = new Fuse(pages, {
keys: ["title", "tags", "category"],
includeScore: true,
});
return fuse;
}, [sidebarContent]);
return (
<>
<SEO {...props.seo} />
<div tw="min-h-screen relative flex">
<Sidebar />
<div tw="flex flex-col flex-1 ">
<Nav />
<MobileNav />
<main tw="flex justify-between px-4 max-w-4xl mx-auto md:px-8 pt-8 pb-12 md:pb-24">
{props.children}
</main>
</div>
</div>
<Modal
title="Search Docs"
isOpen={isSearchOpen}
onClose={() => setIsSearchOpen(false)}
>
<SearchModal fuse={fuse} closeModal={() => setIsSearchOpen(false)} />
</Modal>
</>
);
};