add context hooks and fix new window not appear

This commit is contained in:
Nomi Nonsense (Nonszy) 2025-12-26 19:00:34 +07:00
parent 1215f2f987
commit 107ee8794d
5 changed files with 59 additions and 35 deletions

View File

@ -5,37 +5,41 @@ import HomeText from "@/components/texts/home.mdx"
import Link from "@/components/link"; import Link from "@/components/link";
import { FakeWindow, HomeWindows } from "@/components/windows"; import { FakeWindow, HomeWindows } from "@/components/windows";
import { WindowManagerProvider } from "@/hooks/window-manager";
import { SnowfallBackground } from "@/components/events/christmas"; import { SnowfallBackground } from "@/components/events/christmas";
import { WindowManagerProvider } from "@/hooks/window-manager";
import { ThemeEventsProvider } from "@/hooks/theme-events";
export default function Home() { export default function Home() {
return (<> return (<>
<main className="flex items-center pt-16 md:pt-24 pb-12 px-8 md:px-0 overflow-x-hidden"> <main className="flex items-center pt-16 md:pt-24 pb-12 px-8 md:px-0 overflow-x-hidden">
<SnowfallBackground /> <ThemeEventsProvider>
<WindowManagerProvider> <SnowfallBackground />
<FakeWindow windowText="Homepage"> <WindowManagerProvider>
<HomeWindows /> <FakeWindow windowText="Homepage">
<header className="text-center mb-8"> <HomeWindows />
<h1 className="font-bold text-3xl leading-normal"> <header className="text-center mb-8">
Nonszy Work<span className="text-primary">space</span> <h1 className="font-bold text-3xl leading-normal">
</h1> Nonszy Work<span className="text-primary">space</span>
</header> </h1>
<noscript> </header>
<LandingImage /> <noscript>
</noscript> <LandingImage />
<NolaGlitchClientOnly /> </noscript>
<Sosmed /> <NolaGlitchClientOnly />
<article className="space-y-5 leading-relaxed relative text-sm"> <Sosmed />
<HomeText /> <article className="space-y-5 leading-relaxed relative text-sm">
</article> <HomeText />
<footer className="mt-20 text-center"> </article>
<p>&copy; <span className="text-sm">2025 Nomi Nonszy</span></p> <footer className="mt-20 text-center">
<p className="text-sm"> <p>&copy; <span className="text-sm">2025 Nomi Nonszy</span></p>
<Link href={"/terms"}>Terms</Link> and <Link href={"/privacy"}>Privacy</Link> <p className="text-sm">
</p> <Link href={"/terms"}>Terms</Link> and <Link href={"/privacy"}>Privacy</Link>
</footer> </p>
</FakeWindow> </footer>
</WindowManagerProvider> </FakeWindow>
</WindowManagerProvider>
</ThemeEventsProvider>
</main> </main>
</>); </>);
} }

View File

@ -67,11 +67,9 @@ export const FakeRelativeWindow = ({
} }
useEffect(() => { useEffect(() => {
if (!windowManager.isLocalDataExists) { populateWindow();
if (!currentWindow) populateWindow(); return () => {
return () => { windowManager.remove(windowName);
windowManager.remove(windowName);
}
} }
}, []); }, []);

View File

@ -1,5 +1,6 @@
'use client' 'use client'
import { useThemeEvents } from '@/hooks/theme-events';
import { getEvent } from '@/lib/utils'; import { getEvent } from '@/lib/utils';
import clsx from 'clsx'; import clsx from 'clsx';
import NextImage from 'next/image'; import NextImage from 'next/image';
@ -28,9 +29,9 @@ interface ChristmasProps {
} }
export const ChristmasExclusive = ({ children }: { children: ReactNode }) => { export const ChristmasExclusive = ({ children }: { children: ReactNode }) => {
const isItChristmas = getEvent()?.name == 'christmas'; const eventNow = useThemeEvents()?.event;
if (isItChristmas) return children; if (eventNow?.name == 'christmas') return children;
return null; return null;
} }

View File

@ -84,7 +84,7 @@ export const HomeWindows = () => (
</Link> </Link>
</FakeRelativeWindow> </FakeRelativeWindow>
<FakeRelativeWindow <FakeRelativeWindow
windowText="coral-1.exe" windowText="cube_coral.exe"
className='-left-[75%] top-[1980px] z-10' className='-left-[75%] top-[1980px] z-10'
draggable draggable
> >
@ -98,7 +98,7 @@ export const HomeWindows = () => (
/> />
</FakeRelativeWindow> </FakeRelativeWindow>
<FakeRelativeWindow <FakeRelativeWindow
windowText="ena_spin.obj" windowText="ena_spin.exe"
className="-right-[85%] top-[440px] z-10" className="-right-[85%] top-[440px] z-10"
draggable draggable
> >

View File

@ -0,0 +1,21 @@
'use client'
import { EventsDate } from "@/lib/types";
import { getEvent } from "@/lib/utils";
import { createContext, useContext } from "react";
interface ThemeEventsContextType {
event: EventsDate | undefined
}
const ThemeEventsContext = createContext<ThemeEventsContextType | undefined>(undefined);
export const ThemeEventsProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const eventNow = getEvent();
return <ThemeEventsContext.Provider value={{ event: eventNow }}>
{children}
</ThemeEventsContext.Provider>
}
export const useThemeEvents = () => useContext(ThemeEventsContext);