on 514b5fc help sign in
urbit.org/pages/_app.js
82 lines 1.9 kB history raw
1import "tailwindcss/tailwind.css";
2import { useState, useEffect } from "react";
3import { configure, GlobalHotKeys } from "react-hotkeys";
4import { init } from "@socialgouv/matomo-next";
5import Search from "../components/Search";
6import "../styles/globals.css";
7import "../styles/markdown.css";
8import "../styles/prism.css";
10const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
11const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
13function MyApp({ Component, pageProps }) {
14 const [showSearch, setSearch] = useState(false);
16 useEffect(() => {
17 init({
18 url: MATOMO_URL,
19 siteId: MATOMO_SITE_ID,
20 });
21 });
23 const closeSearch = (event) => {
24 if (event?.preventDefault) {
25 event.preventDefault();
26 }
27 setSearch(false);
28 };
30 const openSearch = (event) => {
31 if (event?.preventDefault) {
32 event.preventDefault();
33 }
34 setSearch(true);
35 };
37 const toggleSearch = (event) => {
38 if (event?.preventDefault) {
39 event.preventDefault();
40 }
41 setSearch((state) => !state);
42 };
44 const keyMap = {
45 closeSearch: ["esc"],
46 toggleSearch: ["command+k", "ctrl+k"],
47 };
49 const handlers = {
50 closeSearch: (event) => closeSearch(event),
51 openSearch: (event) => openSearch(event),
52 toggleSearch: (event) => toggleSearch(event),
53 };
55 configure({
56 // ignoreTags: [],
57 ignoreTags: ["input", "select", "textarea"],
58 ignoreEventsCondition: function () {},
59 });
61 return (
62 <>
63 <GlobalHotKeys keyMap={keyMap} handlers={handlers} />
64 <Search
65 showSearch={showSearch}
66 toggleSearch={toggleSearch}
67 closeSearch={closeSearch}
68 openSearch={openSearch}
69 />
70 <Component
71 {...pageProps}
72 search={{
73 toggleSearch: toggleSearch,
74 closeSearch: closeSearch,
75 openSearch: openSearch,
76 }}
77 />
78 </>
79 );
82export default MyApp;