QLFW-72: фото книги — одинаковые превью и просмотр по нажатию #52

Merged
peppa-bot merged 1 commits from task/qlfw-72 into main 2026-11-18 17:20:40 +05:00
6 changed files with 54 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import { loadLegal } from '@/lib/content'
import { BookLink } from '@/components/BookLink'
import { BookWhere } from '@/components/BookWhere'
import { PhotoGallery } from '@/components/PhotoGallery'
import Image from 'next/image'
import Link from 'next/link'
import { notFound } from 'next/navigation'
@ -12,6 +13,7 @@ import { bookUrl } from '@/lib/home-model'
export const dynamic = 'force-dynamic'
const photos = [1, 2, 3, 4].map(n => ({ src: `/books/serkebayev/photo-${n}.jpg`, alt: `PHOTO ${n}` }))
const path = '/projects/ermek-serkebayev'
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
@ -43,9 +45,7 @@ export default async function BookProject({ params }: { params: Promise<{ locale
</article>
<section className="mt-16">
<h2 className="font-serif text-2xl text-burgundy">{t.book.gallery}</h2>
<div className="mt-6 grid items-start gap-6 sm:grid-cols-2">
{[1, 2, 3, 4].map(n => <Image key={n} src={`/books/serkebayev/photo-${n}.jpg`} alt={`${t.book.photo} ${n}`} width={1000} height={1000} sizes="(min-width: 640px) 50vw, 100vw" className="h-auto w-full" />)}
</div>
<PhotoGallery photos={photos.map(p => ({ ...p, alt: p.alt.replace("PHOTO", t.book.photo) }))} t={t.book} />
</section>
</main>
<Footer t={t} locale={locale} legal={await loadLegal(locale)} />

View File

@ -0,0 +1,41 @@
'use client'
import Image from 'next/image'
import { useCallback, useEffect, useState } from 'react'
type Photo = { src: string; alt: string }
type Labels = { photoClose: string; photoPrev: string; photoNext: string }
export function PhotoGallery({ photos, t }: { photos: Photo[]; t: Labels }) {
const [open, setOpen] = useState<number | null>(null)
const count = photos.length
const step = useCallback((d: number) => setOpen(i => (i === null ? i : (i + d + count) % count)), [count])
useEffect(() => {
if (open === null) return
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') setOpen(null)
else if (e.key === 'ArrowRight') step(1)
else if (e.key === 'ArrowLeft') step(-1)
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, step])
if (count === 0) return null
const btn = 'absolute flex h-11 w-11 items-center justify-center rounded-full bg-paper text-2xl text-graphite'
return <>
<ul className="mt-6 grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4">
{photos.map((p, i) => <li key={p.src}>
<button type="button" onClick={() => setOpen(i)} className="block aspect-square w-full overflow-hidden" aria-label={p.alt}>
<Image src={p.src} alt={p.alt} width={300} height={300} sizes="(min-width: 768px) 25vw, 50vw" className="h-full w-full object-cover" />
</button>
</li>)}
</ul>
{open !== null && <div role="dialog" aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/85 p-4" onClick={() => setOpen(null)}>
<Image src={photos[open].src} alt={photos[open].alt} width={1600} height={1600} sizes="100vw" onClick={e => e.stopPropagation()} className="h-auto max-h-[90vh] w-auto max-w-full object-contain" />
<button type="button" aria-label={t.photoClose} onClick={() => setOpen(null)} className={`${btn} right-4 top-4`}>×</button>
{count > 1 && <>
<button type="button" aria-label={t.photoPrev} onClick={e => { e.stopPropagation(); step(-1) }} className={`${btn} left-3 top-1/2 -translate-y-1/2`}>‹</button>
<button type="button" aria-label={t.photoNext} onClick={e => { e.stopPropagation(); step(1) }} className={`${btn} right-3 top-1/2 -translate-y-1/2`}>›</button>
</>}
</div>}
</>
}

View File

@ -95,6 +95,9 @@ export const en: Dict = {
},
"cover": "Cover",
"photo": "Photo",
"photoClose": "Close",
"photoPrev": "Previous photo",
"photoNext": "Next photo",
"role": "The foundation’s role"
},
footer: 'All rights reserved.',

View File

@ -95,6 +95,9 @@ export const kk: Dict = {
},
"cover": "Мұқаба",
"photo": "Фото",
"photoClose": "Жабу",
"photoPrev": "Алдыңғы фото",
"photoNext": "Келесі фото",
"role": "Қордың рөлі"
},
footer: 'Барлық құқықтар қорғалған.',

View File

@ -95,6 +95,9 @@ export const ru: Dict = {
},
"cover": "Обложка",
"photo": "Фото",
"photoClose": "Закрыть",
"photoPrev": "Предыдущее фото",
"photoNext": "Следующее фото",
"role": "Роль фонда"
},
footer: 'Все права защищены.',

View File

@ -13,7 +13,7 @@ export type Dict = {
mission: { title: string; text: string; missing: string }
directions: { title: string; items: { title: string; text: string }[] }
projects: { title: string; more: string }
book: { title: string; author: string; paragraphs: string[]; get: string; getNote: string; buy: { intro: string; platforms: string[]; storesIntro: string; stores: string[]; note: string } | null; cover: string; photo: string; role: string; translationReview: string; gallery: string; additions: string[] }
book: { title: string; author: string; paragraphs: string[]; get: string; getNote: string; buy: { intro: string; platforms: string[]; storesIntro: string; stores: string[]; note: string } | null; cover: string; photo: string; photoClose: string; photoPrev: string; photoNext: string; role: string; translationReview: string; gallery: string; additions: string[] }
news: { title: string; news: string; event: string }
collaboration: { title: string; text: string; write: string; instagram: string }
contacts: { title: string; description: string; lead: string; emailLabel: string; phoneLabel: string; addressLabel: string; socialsLabel: string }