Skip to content

Commit 0c1fe37

Browse files
committed
Fixed modal slot
1 parent e198134 commit 0c1fe37

11 files changed

Lines changed: 136 additions & 80 deletions

File tree

‎src/app/@modal/default.tsx‎

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1-
export default function DefaultModal() {
2-
return null;
1+
import React, { Suspense } from "react";
2+
import type { Metadata, Viewport } from 'next';
3+
import { Inter } from "next/font/google";
4+
import Link from "next/link";
5+
import { config } from '@fortawesome/fontawesome-svg-core';
6+
import { library } from '@fortawesome/fontawesome-svg-core';
7+
import { fas } from '@fortawesome/free-solid-svg-icons';
8+
import { fab } from '@fortawesome/free-brands-svg-icons';
9+
import Providers from "@app/providers";
10+
import LoadingView from "@components/loading/loading";
11+
import '@fortawesome/fontawesome-svg-core/styles.css';
12+
import "@styles/global.scss";
13+
14+
config.autoAddCss = false;
15+
16+
library.add(fas, fab);
17+
18+
export const metadata: Metadata = {
19+
title: 'Trey | Social, Games, and More Links',
20+
description: 'Profiles for gaming, social media, development, and more.',
21+
category: "Personal Website",
22+
publisher: "@syntax-tm",
23+
creator: "@syntax-tm",
24+
keywords: ['trey', 'discord', 'gundwn', 'gundwn.gg', 'steam', 'xbox', 'syntax-tm', 'github', 'git', 'xmb', 'links', 'social', 'profile', 'games', 'next.js', 'react', 'psp', 'ps3'],
25+
twitter: {
26+
site: "@gundwnsrc",
27+
},
28+
};
29+
30+
const inter = Inter({ subsets: ["latin"] });
31+
32+
export const viewport: Viewport = {
33+
initialScale: 1,
34+
maximumScale: 1,
35+
width: 'device-width',
36+
};
37+
38+
export default function RootLayout({
39+
children,
40+
}: Readonly<{
41+
children: React.ReactNode;
42+
}>) {
43+
44+
const loadingView = (
45+
<>
46+
<LoadingView />
47+
</>
48+
);
49+
50+
return (
51+
<html lang="en">
52+
<body id="body" className={`${inter.className} text-white`}>
53+
<Suspense fallback={loadingView}>
54+
<Providers>
55+
{children}
56+
</Providers>
57+
</Suspense>
58+
{/* Invisible anchor strictly to trigger Next.js route preloading */}
59+
<div style={{ display: 'none' }}>
60+
<Link href="/not-found-page" prefetch={true} />
61+
</div>
62+
</body>
63+
</html>
64+
);
365
}

‎src/app/about/page.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useEffect, useRef } from "react";
44
import useMobileDetect from "@hooks/useMobileDetect";
55
import { AchievementId, useSecret } from "@context/SecretContext";
6-
import { ModalHeader, ModalClose } from "@components/modal/modal";
6+
import { Modal } from "@components/modal/modal";
77

88
function isMultiLine(text: string | undefined) {
99
if (text === undefined) return false;
@@ -112,11 +112,11 @@ export default function AboutPage() {
112112

113113
return (
114114
<>
115-
<ModalHeader title="About" />
116-
<div className=" w-full h-[70%]">
117-
<AboutView />
118-
</div>
119-
<ModalClose />
115+
<Modal title="About">
116+
<div className=" w-full h-[70%]">
117+
<AboutView />
118+
</div>
119+
</Modal>
120120
</>
121121
);
122122
}

‎src/app/help/help.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tr:not(.content-center) > :first-child {
1+
.modal-help tr:not(.content-center) > :first-child {
22
text-align: right;
33
display: flex;
44
justify-content: end;

‎src/app/secrets/page.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"use client";
22

33
import React from "react";
4-
import { ModalHeader, ModalClose } from "@components/modal/modal";
4+
import { Modal } from "@components/modal/modal";
55
import SecretsView from "./secrets-view";
66
import "./secrets.css";
77

88
export default function SecretsPage() {
99

1010
return (
1111
<>
12-
<ModalHeader title="Secrets" />
13-
<div className=" w-full h-[70%]">
14-
<SecretsView />
15-
</div>
16-
<ModalClose />
12+
<Modal title="Secrets">
13+
<div className=" w-full h-[70%]">
14+
<SecretsView />
15+
</div>
16+
</Modal>
1717
</>
1818
);
1919
}

‎src/app/secrets/secrets-view.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
"use client";
2+
13
import { SecretGroupType, useSecret } from "@context/SecretContext";
24
import React, { useEffect, useState } from "react";
35
import SecretView from "./secret-view";
6+
import "./secrets.css";
47

58
const SECRET_TAP_MIN = 5;
69

‎src/components/modal/Modal.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function Modal({ title, children }: { title: string, children: React.Reac
9696
<BackgroundView />
9797
<Clock />
9898
<Menu />
99-
<div className="fixed left-0 top-0 z-100 flex flex-col h-full w-full">
99+
<div className={`modal modal-${title.toLowerCase().replace(/\s+/g, '-')} fixed left-0 top-0 z-100 flex flex-col h-full w-full`}>
100100
<div className="flex flex-col w-screen h-screen bg-black/75 z-100 overflow-none backdrop-blur">
101101
<ModalHeader title={title} />
102102
{children}

‎src/context/BootContext.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
44
import { faSpinner } from "@fortawesome/free-solid-svg-icons";
55
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
6+
import { useSelectedLayoutSegments } from "next/navigation";
67

78
interface BootContextType {
89
isBootVisible: boolean;
@@ -21,6 +22,9 @@ export function BootProvider({ children }: { children: React.ReactNode }) {
2122
const [isBootVisible, setIsBootVisible] = useState(true);
2223
const [isBootTransitioningOut, setIsBootTransitioningOut] = useState(false);
2324

25+
const segment = useSelectedLayoutSegments('modal');
26+
const modal = segment.filter(s => !s.startsWith('(')).length !== 0;
27+
2428
const showBootScreen = useCallback(() => {
2529
setIsBootVisible(true);
2630
setIsBootTransitioningOut(false);
@@ -61,7 +65,7 @@ export function BootProvider({ children }: { children: React.ReactNode }) {
6165
[isBootVisible, isBootTransitioningOut, showBootScreen, hideBootScreen],
6266
);
6367

64-
const shouldShowOverlay = isBootVisible || isBootTransitioningOut;
68+
const shouldShowOverlay = (isBootVisible || isBootTransitioningOut) && !modal;
6569

6670
return <BootContext.Provider value={value}>
6771
{children}

‎src/context/XmbContext.tsx‎

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import React, { createContext, useCallback, useContext, useRef, useState } from "react";
4-
import { useRouter, ReadonlyURLSearchParams } from "next/navigation";
4+
import { useRouter, ReadonlyURLSearchParams, useSelectedLayoutSegments } from "next/navigation";
55
// import { useAudio } from '@context/AudioContext';
66
// import { useSnackbar } from "@context/SnackbarContext";
77
// import { useGamepads } from 'awesome-react-gamepads';
@@ -67,11 +67,14 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
6767
const [currentCategory, setCurrentCategory] = useState<XmbCategory | null>(null);
6868
const [currentItem, setCurrentItem] = useState<XmbItem | null>(null);
6969
const [currentItems, setCurrentItems] = useState<XmbItem[] | null>(null);
70-
const [modal, setModal] = useState<string | null>(null);
70+
//const [modal, setModal] = useState<string | null>(null);
7171
const xmbMenuRef = useRef<XmbMenu | null>(null);
7272
const { play } = useAudio();
7373
const { showSnackbar } = useSnackbar();
7474

75+
const segment = useSelectedLayoutSegments('modal');
76+
const modal = segment.filter(s => !s.startsWith('(')).length !== 0;
77+
7578
if (!xmbItemRef.current) {
7679
xmbItemRef.current = new Map<string, XmbItem>();
7780
}
@@ -98,18 +101,18 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
98101
}
99102

100103
// udpates the selected item (y)
101-
const updateY = (newY: number) => {
104+
const updateY = useCallback((newY: number) => {
102105
// update cache
103106
cache[positionRef.current.x] = newY;
104107
positionRef.current = { ...positionRef.current, y: newY };
105108
if (!currentCategory) return;
106109
const item = currentCategory.items[newY];
107110
setCurrentItem(item);
108111
setY(newY);
109-
};
112+
}, [currentCategory]);
110113

111114
// udpates both the category (x) and restores the previous selected item (y)
112-
const updateX = (newX: number, loadCache: boolean = true) => {
115+
const updateX = useCallback((newX: number, loadCache: boolean = true) => {
113116
const prevY = loadCache ? (cache[newX] ?? 0) : 0;
114117
setX(newX);
115118
positionRef.current = { x: newX, y: prevY };
@@ -118,7 +121,7 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
118121
setCurrentCategory(cat);
119122
setCurrentItems(cat.items);
120123
updateY(prevY);
121-
};
124+
}, [categories, updateY]);
122125

123126
const openItem = useCallback((item: XmbItem) => {
124127
if (item.modal) {
@@ -179,7 +182,7 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
179182
router.push('/?modal=help');
180183
}, []);
181184

182-
const moveUp = () => {
185+
const moveUp = useCallback(() => {
183186
const nextY = y - 1;
184187

185188
play(XMB_AUDIO_SRC);
@@ -189,9 +192,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
189192
updateY(nextY);
190193

191194
return positionRef.current;
192-
};
195+
}, [y, updateY]);
193196

194-
const moveTop = () => {
197+
const moveTop = useCallback(() => {
195198
const nextY = 0;
196199

197200
play(XMB_AUDIO_SRC);
@@ -201,9 +204,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
201204
updateY(nextY);
202205

203206
return positionRef.current;
204-
};
207+
}, [y, updateY]);
205208

206-
const moveDown = () => {
209+
const moveDown = useCallback(() => {
207210
if (!currentCategory) return null;
208211

209212
play(XMB_AUDIO_SRC);
@@ -216,9 +219,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
216219
updateY(nextY);
217220

218221
return positionRef.current;
219-
};
222+
}, [currentCategory, y, updateY]);
220223

221-
const moveBottom = () => {
224+
const moveBottom = useCallback(() => {
222225
if (!currentCategory) return null;
223226

224227
play(XMB_AUDIO_SRC);
@@ -230,9 +233,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
230233
updateY(max);
231234

232235
return positionRef.current;
233-
};
236+
}, [currentCategory, y, updateY]);
234237

235-
const moveLeft = () => {
238+
const moveLeft = useCallback(() => {
236239
if (!categories) return null;
237240

238241
play(XMB_AUDIO_SRC);
@@ -245,9 +248,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
245248
updateX(nextX);
246249

247250
return positionRef.current;
248-
};
251+
}, [x, categories, updateX]);
249252

250-
const moveFirst = () => {
253+
const moveFirst = useCallback(() => {
251254
if (!categories) return null;
252255

253256
play(XMB_AUDIO_SRC);
@@ -260,9 +263,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
260263
updateX(nextX);
261264

262265
return positionRef.current;
263-
};
266+
}, [x, categories, updateX]);
264267

265-
const moveRight = () => {
268+
const moveRight = useCallback(() => {
266269
if (!categories) return null;
267270

268271
play(XMB_AUDIO_SRC);
@@ -276,9 +279,9 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
276279
updateX(nextX);
277280

278281
return positionRef.current;
279-
};
282+
}, [x, categories, updateX]);
280283

281-
const moveLast = () => {
284+
const moveLast = useCallback(() => {
282285
if (!categories) return null;
283286
play(XMB_AUDIO_SRC);
284287

@@ -290,13 +293,7 @@ export function XmbProvider({ children }: { children: React.ReactNode }) {
290293
updateX(max);
291294

292295
return positionRef.current;
293-
};
294-
295-
const onPathChanged = useCallback((path: string, searchParams: ReadonlyURLSearchParams, modal: string | null) => {
296-
setModal(modal);
297-
}, []);
298-
299-
useQuery({ onPathChanged: onPathChanged });
296+
}, [x, categories, updateX]);
300297

301298
const actions = new Map<string, KeyPressAction>();
302299

‎src/hooks/useKeyboard.tsx‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ReadonlyURLSearchParams } from "next/navigation";
3+
import { ReadonlyURLSearchParams, useSelectedLayoutSegments } from "next/navigation";
44
import { useCallback, useEffect, useState } from "react";
55
import useQuery from "./useQuery";
66

@@ -21,13 +21,15 @@ export interface KeyboardOutput {
2121

2222
const useKeyboard = ({ actions, enabledOnModal = false }: KeyboardInput): KeyboardOutput => {
2323
const [keysDown, setKeysDown] = useState<string[]>([]);
24-
const [modal, setModal] = useState<boolean>(false);
24+
//const [modal, setModal] = useState<boolean>(false);
2525

26-
function onPathChanged(p: string, s: ReadonlyURLSearchParams, m: string | null) {
27-
setModal(!!m);
28-
}
26+
const segment = useSelectedLayoutSegments('modal');
27+
const modal = segment.filter(s => !s.startsWith('(')).length !== 0;
2928

30-
useQuery({ onPathChanged: onPathChanged });
29+
// useEffect(() => {
30+
// const isModal = segment !== null;
31+
// setModal(isModal);
32+
// }, [segment]);
3133

3234
const isMapped = useCallback((key: string): boolean => {
3335
return actions.has(key.toLowerCase());
@@ -37,6 +39,8 @@ const useKeyboard = ({ actions, enabledOnModal = false }: KeyboardInput): Keyboa
3739
// key is not mapped, ignore
3840
if (!isMapped(e.key)) return;
3941

42+
if (modal && !enabledOnModal) return;
43+
4044
//e.stopPropagation();
4145
//e.preventDefault();
4246
const updated = keysDown.filter((i) => i !== e.key);
@@ -49,6 +53,8 @@ const useKeyboard = ({ actions, enabledOnModal = false }: KeyboardInput): Keyboa
4953
// key is not mapped, ignore
5054
if (!isMapped(e.key)) return;
5155

56+
if (modal && !enabledOnModal) return;
57+
5258
//e.stopPropagation();
5359
//e.preventDefault();
5460

@@ -66,7 +72,7 @@ const useKeyboard = ({ actions, enabledOnModal = false }: KeyboardInput): Keyboa
6672
action.onKeyPress();
6773

6874
setKeysDown((prevState) => [...prevState, e.key]);
69-
}, [actions, isMapped]);
75+
}, [actions, isMapped, modal]);
7076

7177
useEffect(() => {
7278
if (modal && !enabledOnModal) return;

0 commit comments

Comments
 (0)