Save current look as theme 1, add admin experience skin controls for themes 1-4, fix feedback image sync/lightbox, move hiring to the home bottom, and expose a localhost-only debug orb for instant skin preview. Co-authored-by: Cursor <cursoragent@cursor.com>
136 lines
3.4 KiB
TypeScript
136 lines
3.4 KiB
TypeScript
/**
|
||
* Fullscreen image slideshow for admin feedback / media lists.
|
||
*/
|
||
import { useEffect, useCallback } from 'react'
|
||
import { resolveMediaUrl } from './MediaValue'
|
||
|
||
type Props = {
|
||
urls: string[]
|
||
index: number
|
||
onClose: () => void
|
||
onIndex: (i: number) => void
|
||
}
|
||
|
||
export function ImageLightbox({ urls, index, onClose, onIndex }: Props) {
|
||
const total = urls.length
|
||
const safeIndex = total ? ((index % total) + total) % total : 0
|
||
const src = total ? resolveMediaUrl(urls[safeIndex]) : ''
|
||
|
||
const prev = useCallback(() => {
|
||
if (!total) return
|
||
onIndex((safeIndex - 1 + total) % total)
|
||
}, [onIndex, safeIndex, total])
|
||
|
||
const next = useCallback(() => {
|
||
if (!total) return
|
||
onIndex((safeIndex + 1) % total)
|
||
}, [onIndex, safeIndex, total])
|
||
|
||
useEffect(() => {
|
||
const onKey = (e: KeyboardEvent) => {
|
||
if (e.key === 'Escape') onClose()
|
||
if (e.key === 'ArrowLeft') prev()
|
||
if (e.key === 'ArrowRight') next()
|
||
}
|
||
window.addEventListener('keydown', onKey)
|
||
const prevOverflow = document.body.style.overflow
|
||
document.body.style.overflow = 'hidden'
|
||
return () => {
|
||
window.removeEventListener('keydown', onKey)
|
||
document.body.style.overflow = prevOverflow
|
||
}
|
||
}, [onClose, prev, next])
|
||
|
||
if (!total) return null
|
||
|
||
return (
|
||
<div
|
||
className="com-lightbox"
|
||
role="dialog"
|
||
aria-modal="true"
|
||
aria-label="图片预览"
|
||
onClick={onClose}
|
||
>
|
||
<button
|
||
type="button"
|
||
className="com-lightbox-close"
|
||
aria-label="关闭"
|
||
onClick={(e) => {
|
||
e.stopPropagation()
|
||
onClose()
|
||
}}
|
||
>
|
||
×
|
||
</button>
|
||
{total > 1 ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
className="com-lightbox-nav com-lightbox-prev"
|
||
aria-label="上一张"
|
||
onClick={(e) => {
|
||
e.stopPropagation()
|
||
prev()
|
||
}}
|
||
>
|
||
‹
|
||
</button>
|
||
<button
|
||
type="button"
|
||
className="com-lightbox-nav com-lightbox-next"
|
||
aria-label="下一张"
|
||
onClick={(e) => {
|
||
e.stopPropagation()
|
||
next()
|
||
}}
|
||
>
|
||
›
|
||
</button>
|
||
</>
|
||
) : null}
|
||
<figure
|
||
className="com-lightbox-stage"
|
||
onClick={(e) => e.stopPropagation()}
|
||
>
|
||
<img src={src} alt="" />
|
||
<figcaption>
|
||
{safeIndex + 1} / {total}
|
||
<a href={src} target="_blank" rel="noreferrer">
|
||
原图
|
||
</a>
|
||
</figcaption>
|
||
</figure>
|
||
{total > 1 ? (
|
||
<div
|
||
className="com-lightbox-thumbs"
|
||
onClick={(e) => e.stopPropagation()}
|
||
>
|
||
{urls.map((u, i) => (
|
||
<button
|
||
key={`${u}-${i}`}
|
||
type="button"
|
||
className={
|
||
i === safeIndex
|
||
? 'com-lightbox-thumb is-active'
|
||
: 'com-lightbox-thumb'
|
||
}
|
||
onClick={() => onIndex(i)}
|
||
>
|
||
<img src={resolveMediaUrl(u)} alt="" />
|
||
</button>
|
||
))}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export function feedbackImageUrls(row: Record<string, unknown>): string[] {
|
||
const raw = row.images
|
||
if (!Array.isArray(raw)) return []
|
||
return raw
|
||
.filter((u): u is string => typeof u === 'string')
|
||
.map((u) => u.trim())
|
||
.filter((u) => /^https?:\/\//i.test(u))
|
||
}
|