forked from streamlit/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_app.js
71 lines (56 loc) · 1.94 KB
/
_app.js
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
import { debounce } from "lodash";
import "../styles/globals.css";
import "../components/utilities/searchModal.css";
import "../styles/main.scss";
import "../public/fonts/styles.css";
// Loading indicator
import Router from "next/router";
import NProgress from "nprogress";
import { useState, useEffect } from "react";
import { AppContextProvider } from "../context/AppContext";
Router.events.on("routeChangeStart", () => NProgress.start());
Router.events.on("routeChangeComplete", () => NProgress.done());
Router.events.on("routeChangeError", () => NProgress.done());
function useWindowSize() {
// Initialize state with undefined width/height so server and client renders match
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
const [windowSize, setWindowSize] = useState({
width: undefined,
height: undefined,
});
useEffect(() => {
// Handler to call on window resize
function handleResize() {
// Set window width/height to state
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
}
const debouncedUpdateSize = debounce(handleResize, 200);
// Add event listener
window.addEventListener("resize", debouncedUpdateSize);
// Call handler right away so state gets updated with initial window size
handleResize();
// Remove event listener on cleanup
return () => window.removeEventListener("resize", debouncedUpdateSize);
}, []); // Empty array ensures that effect is only run on mount
useEffect(() => {
if (navigator.platform.match("Mac") === null) {
document.body.classList.add("mac");
}
});
return windowSize;
}
function StreamlitDocs({ Component, pageProps }) {
const size = useWindowSize();
return (
<AppContextProvider>
<Component
window={{ width: size.width, height: size.height }}
{...pageProps}
/>
</AppContextProvider>
);
}
export default StreamlitDocs;