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,12 +5,15 @@ import HomeText from "@/components/texts/home.mdx"
import Link from "@/components/link";
import { FakeWindow, HomeWindows } from "@/components/windows";
import { WindowManagerProvider } from "@/hooks/window-manager";
import { SnowfallBackground } from "@/components/events/christmas";
import { WindowManagerProvider } from "@/hooks/window-manager";
import { ThemeEventsProvider } from "@/hooks/theme-events";
export default function Home() {
return (<>
<main className="flex items-center pt-16 md:pt-24 pb-12 px-8 md:px-0 overflow-x-hidden">
<ThemeEventsProvider>
<SnowfallBackground />
<WindowManagerProvider>
<FakeWindow windowText="Homepage">
@ -36,6 +39,7 @@ export default function Home() {
</footer>
</FakeWindow>
</WindowManagerProvider>
</ThemeEventsProvider>
</main>
</>);
}

View File

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

View File

@ -1,5 +1,6 @@
'use client'
import { useThemeEvents } from '@/hooks/theme-events';
import { getEvent } from '@/lib/utils';
import clsx from 'clsx';
import NextImage from 'next/image';
@ -28,9 +29,9 @@ interface ChristmasProps {
}
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;
}

View File

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