Skip to content

Commit f476c98

Browse files
committed
Refactored, added new modal view, started on snackbar component for notifications.
1 parent c7d3ff5 commit f476c98

22 files changed

Lines changed: 560 additions & 335 deletions

File tree

‎src/app/enums.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
export enum Views {
22
HOME,
3-
DIALOG,
4-
ACCOUNT,
3+
MODAL,
4+
}
5+
6+
export enum ModalViews {
7+
HELP,
8+
59
}
610

711
export enum Direction {

‎src/app/page.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Image from "next/image";
2-
import Background from '@/components/background/background';
3-
import Clock from "@/components/clock/Clock";
2+
import Background from '@components/background/background';
3+
import Clock from "@components/clock/clock";
44
import dynamic from "next/dynamic";
55
import { useRef, useState, ReactNode, useEffect, Dispatch, SetStateAction, CSSProperties } from "react";
66
//import Modal from "@/components/modal/Modal";
77

8-
const Menu = dynamic(() => import('@/components/xmb-menu/xmb-menu'), { ssr: false });
9-
const Modal = dynamic(() => import('@/components/modal/Modal'), { ssr: false })
8+
const Menu = dynamic(() => import('@components/xmb-menu/xmb-menu'), { ssr: false });
9+
const Modal = dynamic(() => import('@components/modal/modal'), { ssr: false })
1010

1111
export default function Home() {
1212

‎src/components/background/background.css‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ body {
6868
transform: translateX(-25%);
6969
}
7070

71+
100% {
72+
transform: translateX(1);
73+
}
74+
}
75+
76+
@keyframes wave2 {
77+
2% {
78+
transform: translateX(1);
79+
}
80+
81+
25% {
82+
transform: translateX(-15%);
83+
}
84+
85+
50% {
86+
transform: translateX(-70%);
87+
}
88+
89+
75% {
90+
transform: translateX(-45%);
91+
}
92+
7193
100% {
7294
transform: translateX(1);
7395
}

‎src/components/clock/Clock.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use client";
1+
"use client"
22

33
import React, { useState, useEffect } from "react";
44
import "./clock.css";

‎src/components/context/app-context.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-case-declarations */
2-
'use client';
2+
"use client"
33

44
import {
55
ReactNode,

‎src/components/modal/Modal.tsx‎

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,111 @@
1-
"use client";
2-
import { useSearchParams } from "next/navigation";
3-
import { HelpModal } from './modal-view';
4-
import "./modal.css";
1+
"use client"
52

6-
export interface ModalProps {
7-
setModalOpen: (arg: boolean) => void;
8-
}
3+
import { ReadonlyURLSearchParams, useRouter, useSearchParams } from "next/navigation";
4+
import { useRef, useState } from "react";
5+
import { HelpView, MobileHelpView } from "./views/help";
6+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
7+
import { faClose } from "@fortawesome/free-solid-svg-icons";
8+
import useKeyboard, { KeyPressAction } from "@hooks/useKeyboard";
9+
import useMobileDetect from "@hooks/useMobileDetect";
10+
import useQuery from "@hooks/useQuery";
11+
import { useWindowSize } from "@uidotdev/usehooks";
12+
import Link from "next/link";
13+
import { CopyView } from "./views/copy";
14+
import accounts from "@/config/accounts.json";
15+
import "./modal.css";
916

1017
export default function Modal() {
1118
const searchParams = useSearchParams();
12-
const modal = searchParams.get("modal");
19+
const modalParam = searchParams.get("modal");
20+
const audioRef = useRef<HTMLAudioElement | null>(null);
21+
const router = useRouter();
22+
const size = useWindowSize();
23+
const mobileDetect = useMobileDetect();
24+
25+
const [modal, setModal] = useState<string | null>(modalParam);
26+
27+
const play = () => {
28+
if (audioRef.current) {
29+
audioRef.current.volume = 1;
30+
audioRef.current.play();
31+
} else {
32+
// Throw error
33+
}
34+
};
35+
36+
function onEsc() {
37+
play();
38+
39+
router.push('/');
40+
}
41+
42+
function onPathChanged(p: string, s: ReadonlyURLSearchParams, m: string | null) {
43+
setModal(m);
44+
}
45+
46+
useQuery({ onPathChanged: onPathChanged });
47+
48+
const actions = new Map<string, KeyPressAction>();
49+
50+
if (modal) {
51+
actions.set('escape', { repeat: false, onKeyPress: onEsc });
52+
}
53+
54+
useKeyboard({ actions: actions, enabledOnModal: true });
1355

1456
let view;
57+
let title;
1558

1659
if (modal === 'help') {
17-
view = <HelpModal />;
18-
}
19-
else if (modal === 'true') {
20-
view = <HelpModal />;
60+
title = 'Help';
61+
if (mobileDetect.isMobile()) {
62+
view = <MobileHelpView />;
63+
} else {
64+
view = <HelpView />;
65+
}
66+
} else if (modal === 'bnet') {
67+
title = 'Battle.Net';
68+
view = <CopyView title="BattleTag:" value={accounts.battleNet.id} />
2169
}
2270

2371
return (
2472
<>
2573
{modal && (
26-
view
74+
<div>
75+
{/* <div className="right-0 top-0 absolute w-[30px] m-5 aspect-square z-[200]">
76+
<FontAwesomeIcon icon={faClose} className="w-full h-full" />
77+
</div> */}
78+
<dialog className="absolute left-0 top-0 w-full h-full bg-black bg-opacity-75 z-[100] overflow-none backdrop-blur flex">
79+
<audio ref={audioRef} src='/audio/nav.mp3' />
80+
<div className="absolute left-0 items-end w-full h-[15%] grid grid-cols-1 content-end">
81+
<p className="modal-title text-xl">
82+
{title}
83+
</p>
84+
<hr className="w-full" />
85+
</div>
86+
{view}
87+
<div className="absolute left-0 bottom-0 items-start w-full h-[15%] grid grid-cols-1 content-start">
88+
<hr className="w-full" />
89+
<span className="text-white mt-[1em] ml-[0.5em] text-center modal-action">
90+
{/* need to set the href so that the user can close modal by clicking on the buttton */}
91+
<Link href={'/'}>
92+
{mobileDetect.isMobile() && (
93+
<div className="text-xl items-center justify-items-center align-items-center inline-flex">
94+
<FontAwesomeIcon icon={faClose} className="w-7 h-7 aspect-square inline-flex my-auto modal-action" />
95+
<span className="mx-2 my-auto">close</span>
96+
</div>
97+
)}
98+
{mobileDetect.isDesktop() && (
99+
<>
100+
<kbd className="px-2 py-1.5 text-xs text-gray-800 bg-gray-100 mx-[3px] border border-gray-200 rounded-lg dark:bg-gray-400/25 dark:text-white dark:border-gray-500/25">Esc</kbd> close
101+
</>
102+
)}
103+
104+
</Link>
105+
</span>
106+
</div>
107+
</dialog>
108+
</div>
27109
)}
28110
</>
29111
);

0 commit comments

Comments
 (0)