"use client" import { useEffect, useRef } from "react" import Image from "next/image" import { X, ChevronLeft, ChevronRight, Camera, MapPin, Calendar } from "lucide-react" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Card, CardContent } from "@/components/ui/card" import { useDrag } from "@use-gesture/react" import { useSpring, animated } from "react-spring" import { Photo } from '@/lib/queries' interface PhotoModalProps { photo: Photo onClose: () => void onPrev: () => void onNext: () => void } export function PhotoModal({ photo, onClose, onPrev, onNext }: PhotoModalProps) { const containerRef = useRef(null) // 触摸手势支持 const [{ x }, api] = useSpring(() => ({ x: 0 })) const bind = useDrag( ({ down, movement: [mx], velocity: [vx], direction: [xDir], cancel }) => { // 如果滑动速度足够快或者滑动距离超过阈值,触发切换 const trigger = Math.abs(mx) > window.innerWidth * 0.3 || Math.abs(vx) > 0.5 if (trigger && !down) { // 根据滑动方向决定前进或后退 if (xDir > 0) { onPrev() // 向右滑动,显示上一张 } else { onNext() // 向左滑动,显示下一张 } cancel() // 取消手势 } // 设置拖拽动画 api.start({ x: down ? mx : 0, immediate: down, config: { tension: 300, friction: 30 } }) }, { axis: 'x', bounds: { left: -window.innerWidth, right: window.innerWidth }, rubberband: true, filterTaps: true, } ) useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { switch (e.key) { case "Escape": onClose() break case "ArrowLeft": onPrev() break case "ArrowRight": onNext() break } } document.addEventListener("keydown", handleKeyDown) document.body.style.overflow = "hidden" return () => { document.removeEventListener("keydown", handleKeyDown) document.body.style.overflow = "unset" } }, [onClose, onPrev, onNext]) return (
{/* Close button */} {/* Navigation buttons */}
{/* Main image */}
{photo.title}
{/* Photo information */}
{/* Title and description */}

{photo.title}

{photo.description}

{/* Tags */}

标签

{photo.tags.map((tag: string) => ( {tag} ))}
{/* Date and location */}
拍摄时间:{photo.date}
拍摄地点:{photo.exif.location}
{/* EXIF information */}

拍摄参数

相机: {photo.exif.camera}
镜头: {photo.exif.lens}
参数: {photo.exif.settings}
{/* Keyboard shortcuts and gestures */}

操作说明

ESC - 关闭
← → - 切换图片
左右滑动 - 切换图片
拖拽图片 - 切换图片
) }