add context hooks and fix new window not appear
This commit is contained in:
parent
1215f2f987
commit
107ee8794d
@ -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>
|
||||
</>);
|
||||
}
|
||||
|
||||
@ -67,12 +67,10 @@ export const FakeRelativeWindow = ({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!windowManager.isLocalDataExists) {
|
||||
if (!currentWindow) populateWindow();
|
||||
populateWindow();
|
||||
return () => {
|
||||
windowManager.remove(windowName);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
>
|
||||
|
||||
21
src/hooks/theme-events.tsx
Normal file
21
src/hooks/theme-events.tsx
Normal 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);
|
||||
Loading…
x
Reference in New Issue
Block a user