Skip to content

Commit b4a0f14

Browse files
update gallery to have image open in modal
1 parent 644837f commit b4a0f14

File tree

5 files changed

+147
-16
lines changed

5 files changed

+147
-16
lines changed

.astro/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/// <reference types="astro/client" />
2+
/// <reference path="content.d.ts" />

public/css/style.css

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
box-sizing: border-box;
2525
}
2626

27+
p {
28+
font-size: 18px; /* Example: Sets the font size to 16 pixels */
29+
}
30+
2731
/* text weblinks */
2832
main a {
2933
color: grey;
@@ -296,7 +300,72 @@ gradio-app .example-row {
296300
width: 100% !important;
297301
}
298302

299-
303+
/* src/styles/gallery.css */
304+
/* Modal container using flex to center content */
305+
.modal {
306+
display: none;
307+
position: fixed;
308+
z-index: 1000;
309+
left: 0;
310+
top: 0;
311+
width: 100%;
312+
height: 100%;
313+
background-color: rgba(0,0,0,0.9);
314+
display: flex;
315+
align-items: center;
316+
justify-content: center;
317+
}
318+
319+
/* Modal container using flex to center content */
320+
.modal {
321+
display: none; /* Hidden by default */
322+
position: fixed;
323+
z-index: 1000;
324+
left: 0;
325+
top: 0;
326+
width: 100%;
327+
height: 100%;
328+
background-color: rgba(0,0,0,0.9);
329+
align-items: center;
330+
justify-content: center;
331+
}
332+
333+
/* Only display the modal when it has the active class */
334+
.modal.active {
335+
display: flex;
336+
}
337+
338+
/* Modal image styling */
339+
.modal-content {
340+
max-width: 90%;
341+
max-height: 90%;
342+
}
343+
344+
/* Close button styling */
345+
.close {
346+
position: absolute;
347+
top: 20px;
348+
right: 35px;
349+
color: #fff;
350+
font-size: 40px;
351+
font-weight: bold;
352+
cursor: pointer;
353+
}
354+
.close:hover,
355+
.close:focus {
356+
color: #bbb;
357+
text-decoration: none;
358+
}
359+
360+
/* Optional: style for clickable images */
361+
.clickable {
362+
cursor: pointer;
363+
transition: transform 0.2s;
364+
}
365+
.clickable:hover {
366+
transform: scale(1.03);
367+
}
368+
300369
/* Responsive Adjustments */
301370
@media (max-width: 768px) {
302371
header .container {
@@ -311,3 +380,32 @@ gradio-app .example-row {
311380
margin: 5px;
312381
}
313382
}
383+
384+
/* Full-screen overlay for loading modal */
385+
.loading-modal {
386+
position: fixed;
387+
top: 0;
388+
left: 0;
389+
width: 100%;
390+
height: 100%;
391+
background: rgba(0, 0, 0, 0.2); /* very faint overlay */
392+
display: flex;
393+
align-items: center;
394+
justify-content: center;
395+
z-index: 2000; /* Ensure it sits on top */
396+
}
397+
398+
/* Simple spinner */
399+
.spinner {
400+
border: 8px solid rgba(255, 255, 255, 0.3);
401+
border-top: 8px solid #fff;
402+
border-radius: 50%;
403+
width: 60px;
404+
height: 60px;
405+
animation: spin 1s linear infinite;
406+
}
407+
408+
@keyframes spin {
409+
0% { transform: rotate(0deg); }
410+
100% { transform: rotate(360deg); }
411+
}

src/pages/gallery/[page].astro

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,27 @@
22
import Layout from '../../layouts/Layout.astro';
33
import { getImagesInfo } from '../../utils/getImagesInfo';
44
5-
// Generate static paths for each gallery page.
65
export async function getStaticPaths() {
7-
// Define rootDirectory inside getStaticPaths so it's available here.
86
const rootDirectory = Astro.root ?? process.cwd();
97
const { totalPages } = getImagesInfo(rootDirectory);
108
return Array.from({ length: totalPages }, (_, i) => ({
119
params: { page: String(i + 1) }
1210
}));
1311
}
1412
15-
// In the main code, define rootDirectory again.
1613
const rootDirectory = Astro.root ?? process.cwd();
1714
const { files, perPage, totalPages } = getImagesInfo(rootDirectory);
18-
19-
// Retrieve the current page number from URL parameters.
2015
const { page } = Astro.params;
2116
const currentPage = parseInt(page, 10);
22-
23-
// Determine which images to show on this page.
2417
const start = (currentPage - 1) * perPage;
2518
const images = files.slice(start, start + perPage);
2619
---
2720

2821
<Layout title={`Gallery - Page ${currentPage}`} activePage="gallery">
22+
<br>
23+
<br>
2924
<h1>My Photos - Page {currentPage}</h1>
30-
<p>Here is a collection of pictures I have taken over the years to record my memories, experiences and travels.</p>
25+
<p>Here are pictures I have enjoyed taking over the years to record my memories, experiences and travels.</p>
3126
<br>
3227
<br>
3328
<nav class="pagination">
@@ -52,7 +47,7 @@ const images = files.slice(start, start + perPage);
5247

5348
<div class="gallery-full">
5449
{images.map((image) => (
55-
<img src={`/images/${image}`} alt="Gallery image" loading="lazy" />
50+
<img src={`/images/${image}`} alt="Gallery image" loading="lazy" class="clickable" />
5651
))}
5752
</div>
5853

@@ -76,4 +71,36 @@ const images = files.slice(start, start + perPage);
7671
<a href={`/gallery/${currentPage + 1}`}>Next &raquo;</a>
7772
)}
7873
</nav>
74+
75+
<!-- Modal for Enlarged Image -->
76+
<div id="modal" class="modal">
77+
<span class="close">&times;</span>
78+
<img class="modal-content" id="modal-img" alt="" src=""/>
79+
</div>
80+
81+
<script>
82+
document.addEventListener("DOMContentLoaded", () => {
83+
const modal = document.getElementById("modal");
84+
const modalImg = document.getElementById("modal-img");
85+
const closeBtn = document.querySelector(".close");
86+
87+
document.querySelectorAll('.gallery-full img.clickable').forEach(img => {
88+
img.addEventListener('click', () => {
89+
modal.style.display = "flex"; // Use flex to center the content
90+
modalImg.src = img.src;
91+
});
92+
});
93+
94+
closeBtn.addEventListener('click', () => {
95+
modal.style.display = "none";
96+
});
97+
98+
// Close modal when clicking outside the image
99+
modal.addEventListener('click', (e) => {
100+
if (e.target === modal) {
101+
modal.style.display = "none";
102+
}
103+
});
104+
});
105+
</script>
79106
</Layout>

src/pages/gallery/index.astro

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
<html lang="en">
55
<head>
66
<meta charset="UTF-8" />
7-
<!-- Immediately redirect to /gallery/1 -->
8-
<meta http-equiv="refresh" content="0; url=/gallery/1" />
9-
<link rel="canonical" href="/gallery/1" />
10-
<title>Redirecting...</title>
7+
<title>Loading Gallery...</title>
118
</head>
129
<body>
13-
<p>Redirecting to <a href="/gallery/1">Gallery Page 1</a>...</p>
10+
<div class="loading-modal">
11+
<div class="spinner"></div>
12+
</div>
13+
<script>
14+
// Redirect after a short delay (e.g., 300ms)
15+
setTimeout(() => {
16+
window.location.href = '/gallery/1';
17+
}, 100);
18+
</script>
1419
</body>
1520
</html>

src/utils/getImagesInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function getImagesInfo(root = process.cwd()) {
1414
files.sort();
1515

1616
// Set the number of images per page.
17-
const perPage = 50;
17+
const perPage = 48;
1818
const totalPages = Math.ceil(files.length / perPage);
1919

2020
return { files, perPage, totalPages };

0 commit comments

Comments
 (0)