Skip to content

Commit 8e7d5ff

Browse files
committed
Modal pop up
Modal will now appear when clicking on a link. As of now, no downloads are available, but the link technically works.
1 parent 9f45526 commit 8e7d5ff

File tree

2 files changed

+116
-56
lines changed

2 files changed

+116
-56
lines changed

app/ui/modal.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use client';
2+
import { useEffect } from 'react';
3+
4+
type Props = {
5+
slug: string;
6+
onClose: () => void;
7+
};
8+
9+
export default function Modal({ slug, onClose }: Props) {
10+
const imgBase = `/Source_Skyboxes_NextJS/skyboxes/${slug}/images`;
11+
12+
useEffect(() => {
13+
const original = document.documentElement.style.overflow;
14+
document.documentElement.style.overflow = 'hidden';
15+
16+
return () => {
17+
document.documentElement.style.overflow = original;
18+
};
19+
}, []);
20+
21+
useEffect(() => {
22+
const handler = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
23+
window.addEventListener('keydown', handler);
24+
return () => window.removeEventListener('keydown', handler);
25+
}, [onClose]);
26+
27+
return (
28+
<div
29+
onClick={onClose}
30+
className="fixed inset-0 z-50 bg-black/75 backdrop-blur-sm flex justify-center items-center p-4"
31+
>
32+
<article
33+
onClick={e => e.stopPropagation()}
34+
className="
35+
w-full max-w-[90vw]
36+
sm:max-w-xl
37+
md:max-w-2xl
38+
lg:max-w-3xl
39+
xl:max-w-4xl
40+
max-h-[70vh] overflow-y-auto
41+
bg-neutral-900 rounded-lg shadow-xl ring-1 ring-neutral-700/60
42+
"
43+
>
44+
<img
45+
src={`${imgBase}/previews/1.webp`}
46+
alt={`${slug} preview`}
47+
className="w-full"
48+
/>
49+
50+
<div className="p-4">
51+
<h2 className="text-xl font-bold mb-2">{slug}</h2>
52+
<a
53+
href={`/Source_Skyboxes_NextJS/skyboxes/${slug}/download/${slug}.7z`}
54+
className="underline text-blue-300"
55+
download
56+
>
57+
Download
58+
</a>
59+
</div>
60+
</article>
61+
</div>
62+
);
63+
}

app/ui/skyboxcard.tsx

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,61 @@
1-
import Image from 'next/image';
2-
import Link from 'next/link';
1+
'use client';
32

4-
type Props = {
5-
slug: string;
6-
};
3+
import Image from 'next/image';
4+
import Modal from './modal';
5+
import { useState } from 'react';
76

8-
export default function SkyboxCard({ slug }: Props) {
9-
const imgBase = `/Source_Skyboxes_NextJS/skyboxes/${slug}/images`;
10-
const details = `/${slug}`;
7+
type Props = { slug: string };
118

12-
const thumbnail = `${imgBase}/thumbnail.webp`;
9+
export default function SkyboxCard({ slug }: Props) {
10+
const [open, setOpen] = useState(false);
11+
const imgBase = `/Source_Skyboxes_NextJS/skyboxes/${slug}/images`;
1312

14-
//placeholder
15-
const description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
16-
17-
return (
18-
<Link href={details}>
13+
return (
14+
<>
15+
<button
16+
onClick={() => setOpen(true)}
17+
className="group block w-full text-left"
18+
>
1919
<article
20+
className="
21+
relative flex flex-col
22+
bg-neutral-800 ring-1 ring-neutral-700/60
23+
shadow-lg shadow-black/40
24+
transition hover:scale-105
25+
overflow-hidden aspect-[16/9] w-full
26+
"
27+
style={{
28+
backgroundImage: `url(${imgBase}/thumbnail.webp)`,
29+
backgroundSize: 'cover',
30+
backgroundPosition: 'center',
31+
}}
32+
>
33+
<Image
34+
src={`${imgBase}/thumbnail.webp`}
35+
alt={`${slug} preview`}
36+
fill
37+
className="opacity-0"
38+
unoptimized
39+
/>
40+
41+
<div
2042
className="
21-
group
22-
relative flex flex-col items-center
23-
bg-neutral-800 ring-1 ring-neutral-700/60
24-
shadow-lg shadow-black/40
25-
transition duration-150 hover:scale-105
26-
overflow-hidden
27-
aspect-[16/9]
43+
absolute inset-x-0 bottom-0
44+
translate-y-0 opacity-100
45+
md:translate-y-full md:opacity-0
46+
md:group-hover:translate-y-0 md:group-hover:opacity-100
47+
bg-black/60 backdrop-blur-xs px-3 py-2
48+
transition
2849
"
29-
style={{
30-
backgroundImage: `url(${thumbnail})`,
31-
backgroundSize: 'cover',
32-
backgroundPosition: 'center',
33-
}}
34-
>
35-
36-
{/* Visually hidden image for SEO/alt text */}
37-
<Image
38-
src={thumbnail}
39-
alt={`${slug} preview`}
40-
fill
41-
className="opacity-0"
42-
unoptimized
43-
/>
44-
<div
45-
className="
46-
absolute inset-x-0 bottom-0
47-
translate-y-0 opacity-100
48-
md:translate-y-full
49-
md:opacity-0
50-
md:group-hover:translate-y-0
51-
md:group-hover:opacity-100
52-
bg-black/60 backdrop-blur-xs
53-
px-3 py-2
54-
transition duration-150
55-
"
56-
>
57-
<h2 className="text-sm font-semibold text-neutral-100 truncate">
58-
{slug}
59-
</h2>
60-
</div>
50+
>
51+
<h2 className="text-sm font-semibold text-neutral-100 truncate">
52+
{slug}
53+
</h2>
54+
</div>
6155
</article>
62-
</Link>
63-
);
64-
}
56+
</button>
57+
58+
{open && <Modal slug={slug} onClose={() => setOpen(false)} />}
59+
</>
60+
);
61+
}

0 commit comments

Comments
 (0)