From 107ee8794d8971e5b3e438e8e80b53948341c22f Mon Sep 17 00:00:00 2001 From: nomi-nonsz Date: Fri, 26 Dec 2025 19:00:34 +0700 Subject: [PATCH] add context hooks and fix new window not appear --- src/app/page.tsx | 56 +++++++++++++++-------------- src/components/client-windows.tsx | 8 ++--- src/components/events/christmas.tsx | 5 +-- src/components/windows.tsx | 4 +-- src/hooks/theme-events.tsx | 21 +++++++++++ 5 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 src/hooks/theme-events.tsx diff --git a/src/app/page.tsx b/src/app/page.tsx index 5fb1c82..de9e337 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,37 +5,41 @@ 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 (<>
- - - - -
-

- Nonszy Workspace -

-
- - - -
- -
-
-

© 2025 Nomi Nonszy

-

- Terms and Privacy -

-
-
-
+ + + + + +
+

+ Nonszy Workspace +

+
+ + + +
+ +
+
+

© 2025 Nomi Nonszy

+

+ Terms and Privacy +

+
+
+
+
); } diff --git a/src/components/client-windows.tsx b/src/components/client-windows.tsx index 06c23f6..170332a 100644 --- a/src/components/client-windows.tsx +++ b/src/components/client-windows.tsx @@ -67,11 +67,9 @@ export const FakeRelativeWindow = ({ } useEffect(() => { - if (!windowManager.isLocalDataExists) { - if (!currentWindow) populateWindow(); - return () => { - windowManager.remove(windowName); - } + populateWindow(); + return () => { + windowManager.remove(windowName); } }, []); diff --git a/src/components/events/christmas.tsx b/src/components/events/christmas.tsx index 0e43548..ead5800 100644 --- a/src/components/events/christmas.tsx +++ b/src/components/events/christmas.tsx @@ -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; } diff --git a/src/components/windows.tsx b/src/components/windows.tsx index e3cfcc3..3577545 100644 --- a/src/components/windows.tsx +++ b/src/components/windows.tsx @@ -84,7 +84,7 @@ export const HomeWindows = () => ( @@ -98,7 +98,7 @@ export const HomeWindows = () => ( /> diff --git a/src/hooks/theme-events.tsx b/src/hooks/theme-events.tsx new file mode 100644 index 0000000..e04f0c9 --- /dev/null +++ b/src/hooks/theme-events.tsx @@ -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(undefined); + +export const ThemeEventsProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { + const eventNow = getEvent(); + + return + {children} + +} + +export const useThemeEvents = () => useContext(ThemeEventsContext); \ No newline at end of file