Skip to content

Commit

Permalink
Merge pull request #24 from SweetmanTech/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
sweetmantech authored Dec 29, 2023
2 parents 34833f2 + bac4d25 commit d46e8a1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 32 deletions.
43 changes: 26 additions & 17 deletions components/Layout/BaseLayout/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ import CameraFeed from "../../CameraFeed"
import CameraFeedProvider from "../../../providers/CameraFeedProvider"
import DateSelect from "../../DateSelect"
import DateSelectProvider from "../../../providers/DateSelectProvider"
import { usePageLoad } from "../../../providers/PageLoadProvider"

const BaseLayout = ({ entered = false, children }: ILayout) => (
<div className="w-screen h-screen p-[50px]">
<div className="flex flex-col h-[calc(100vh-145px)] gap-y-[5px]">
<Navbar />
<div className="flex flex-grow h-full gap-x-[20px]">
<div className="flex-grow w-[calc(100vw-490px)]">{children}</div>
<div className="w-[370px] flex flex-col gap-y-[20px]">
<div className="border-[#d2d2d2] border-[2px] h-[calc(100%-280px)] py-[10px] overflow-y-auto">
<CameraFeedProvider>{entered && <CameraFeed />}</CameraFeedProvider>
</div>
<div className="border-[#d2d2d2] border-[2px]">
<DateSelectProvider>
<DateSelect />
</DateSelectProvider>
</div>
const BaseLayout = ({ children }: ILayout) => {
const { entered } = usePageLoad()

return (
<div className="w-screen h-screen p-[50px]">
<div className="flex flex-col h-[calc(100vh-145px)] gap-y-[5px]">
{entered && <Navbar />}
<div className="flex flex-grow h-full gap-x-[20px]">
<div className="flex-grow w-[calc(100vw-490px)]">{children}</div>
{entered && (
<div className="w-[370px] flex flex-col gap-y-[20px]">
<div className="border-[#d2d2d2] border-[2px] h-[calc(100%-280px)] py-[10px] overflow-y-auto">
<CameraFeedProvider>
<CameraFeed />
</CameraFeedProvider>
</div>
<div className="border-[#d2d2d2] border-[2px]">
<DateSelectProvider>
<DateSelect />
</DateSelectProvider>
</div>
</div>
)}
</div>
</div>
</div>
</div>
)
)
}

export default BaseLayout
4 changes: 2 additions & 2 deletions components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Container entered={entered}>{children}</Container>
return <Container>{children}</Container>
}

export default Layout
1 change: 0 additions & 1 deletion components/Layout/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import { ReactNode } from "react"

export interface ILayout {
children: ReactNode
entered?: boolean
}
11 changes: 6 additions & 5 deletions components/Pages/LandingPage/LandingPage.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Layout type={isMobile ? "mobile" : "base"} entered={entered}>
<Layout type={isMobile ? "mobile" : "base"}>
<SeoHead title="HENO. HOME" />

<div
Expand Down
17 changes: 10 additions & 7 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Analytics } from "@vercel/analytics/react"
import Swiper, { Mousewheel } from "swiper"
import { ThemeProvider } from "../providers/ThemeProvider"
import { TITLE } from "../lib/consts"
import PageLoadProvider from "../providers/PageLoadProvider"

Swiper.use([Mousewheel])

Expand Down Expand Up @@ -54,13 +55,15 @@ function MyApp({ Component, pageProps }: AppProps) {
overlayBlur: "small",
})}
>
<ThemeProvider>
<SessionProvider>
<Component {...pageProps} />
<ToastContainer />
<Analytics />
</SessionProvider>
</ThemeProvider>
<PageLoadProvider>
<ThemeProvider>
<SessionProvider>
<Component {...pageProps} />
<ToastContainer />
<Analytics />
</SessionProvider>
</ThemeProvider>
</PageLoadProvider>
</RainbowKitProvider>
</WagmiConfig>
)
Expand Down
30 changes: 30 additions & 0 deletions providers/PageLoadProvider.tsx
Original file line number Diff line number Diff line change
@@ -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 <PageLoadContext.Provider value={value}>{children}</PageLoadContext.Provider>
}

export const usePageLoad = () => {
const context = useContext(PageLoadContext)
if (!context) {
throw new Error("usePageLoad must be used within a PageLoadProvider")
}
return context
}

export default PageLoadProvider

0 comments on commit d46e8a1

Please sign in to comment.