-
{children}
-
-
- {entered && }
-
-
-
-
-
-
+const BaseLayout = ({ children }: ILayout) => {
+ const { entered } = usePageLoad()
+
+ return (
+
+
+ {entered &&
}
+
+
{children}
+ {entered && (
+
+ )}
-
-)
+ )
+}
export default BaseLayout
diff --git a/components/Layout/index.tsx b/components/Layout/index.tsx
index 33840c97..5dcc1de3 100644
--- a/components/Layout/index.tsx
+++ b/components/Layout/index.tsx
@@ -11,10 +11,10 @@ interface ILayoutFactory extends ILayout {
type: keyof typeof layoutContainers
}
-function Layout({ children, type, entered = false }: ILayoutFactory) {
+function Layout({ children, type }: ILayoutFactory) {
const Container = layoutContainers[type]
- return
{children}
+ return
{children}
}
export default Layout
diff --git a/components/Layout/types.ts b/components/Layout/types.ts
index 27f3cacd..283a3025 100644
--- a/components/Layout/types.ts
+++ b/components/Layout/types.ts
@@ -2,5 +2,4 @@ import { ReactNode } from "react"
export interface ILayout {
children: ReactNode
- entered?: boolean
}
diff --git a/components/Pages/LandingPage/LandingPage.tsx b/components/Pages/LandingPage/LandingPage.tsx
index 1dd90f1a..cfd7e1f0 100644
--- a/components/Pages/LandingPage/LandingPage.tsx
+++ b/components/Pages/LandingPage/LandingPage.tsx
@@ -1,29 +1,30 @@
-import { useState, useEffect } from "react"
+import { useEffect } from "react"
import LandingCard from "../../LandingCard"
import Layout from "../../Layout"
import SeoHead from "../../SeoHead"
import LoadingPage from "../../LoadingPage"
import useIsMobile from "../../../hooks/useIsMobile"
+import { usePageLoad } from "../../../providers/PageLoadProvider"
const LandingPage = () => {
- const [entered, setEntered] = useState(false)
+ const { entered, setEntered } = usePageLoad()
+
const isMobile = useIsMobile()
useEffect(() => {
- // Add event listener for the entire page
const handlePageClick = () => setEntered(true)
if (!entered) {
window.addEventListener("click", handlePageClick)
}
- // Cleanup the event listener
return () => {
window.removeEventListener("click", handlePageClick)
}
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [entered])
return (
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
)
diff --git a/providers/PageLoadProvider.tsx b/providers/PageLoadProvider.tsx
new file mode 100644
index 00000000..7c26003c
--- /dev/null
+++ b/providers/PageLoadProvider.tsx
@@ -0,0 +1,30 @@
+import { createContext, useContext, useMemo, useState } from "react"
+
+const PageLoadContext = createContext(null)
+
+const PageLoadProvider = ({ children }) => {
+ const [entered, setEntered] = useState(false)
+
+ const value = useMemo(
+ () => ({
+ entered,
+ setEntered
+ }),
+ [
+ entered,
+ setEntered
+ ],
+ )
+
+ return
{children}
+}
+
+export const usePageLoad = () => {
+ const context = useContext(PageLoadContext)
+ if (!context) {
+ throw new Error("usePageLoad must be used within a PageLoadProvider")
+ }
+ return context
+}
+
+export default PageLoadProvider