-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.tsx
64 lines (55 loc) · 1.65 KB
/
Layout.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
"use client";
import { useDarkMode } from "@/context";
import { DARK_SCREEN } from "@rp/constants";
import { FC, ReactNode, useEffect, useState } from "react";
import { Flashlight } from "./Flashlight";
export const Layout: FC<{ children: ReactNode }> = ({ children }) => {
const [position, setPosition] = useState<{ x: number; y: number }>({
x: 0,
y: 0,
});
const { darkness, setDarkness, setDarkMode } = useDarkMode();
const updateDarkness = () => {
// const isLargeScreen = window.matchMedia("(min-width: 786px)").matches;
// if (isLargeScreen) {
// setDarkness(DARK_SCREEN);
// setDarkMode(true);
// } else {
// setDarkness(LIGHT_SCREEN);
// setDarkMode(false);
// }
setDarkness(DARK_SCREEN);
setDarkMode(true);
};
useEffect(() => {
if (typeof window !== "undefined") {
updateDarkness();
window.addEventListener("resize", updateDarkness);
return () => window.removeEventListener("resize", updateDarkness);
}
}, []);
useEffect(() => {
if (typeof window !== "undefined") {
const handleMouseMove = (event: MouseEvent) => {
setPosition({ x: event.clientX, y: event.clientY });
};
window.addEventListener("mousemove", handleMouseMove);
return () => {
window.removeEventListener("mousemove", handleMouseMove);
};
}
}, []);
return (
<>
<Flashlight
enableMouse={false}
showCursor={true}
initialPosition={position}
moveTo={position}
darkness={darkness}
>
<div className="bg-wallpaper h-screen overflow-auto">{children}</div>
</Flashlight>
</>
);
};