11import { useState , useEffect } from 'react'
2- import { useParams , useNavigate } from '@tanstack/react-router'
2+ import { useParams , useLocation , useNavigate } from '@tanstack/react-router'
33import { X , ChevronLeft , ChevronRight , Heart } from 'lucide-react'
44import { motion , AnimatePresence } from 'framer-motion'
55import PostInfoSection from './PostInfoSection'
@@ -17,6 +17,7 @@ export interface PostData {
1717
1818export default function PostDetail ( ) {
1919 const { post_id : postId } = useParams ( { from : '/_app/p/$post_id' } )
20+ const location = useLocation ( )
2021 const navigate = useNavigate ( )
2122
2223 const [ postData , setPostData ] = useState < PostData | null > ( null )
@@ -34,7 +35,19 @@ export default function PostDetail() {
3435 } , [ postId ] )
3536
3637 const images = postData ?. images || [ ]
37- const handleClose = ( ) => navigate ( { to : '..' } )
38+ const handleClose = ( ) => {
39+ const returnToPath = location . search . returnToPath
40+ const returnToSearch = location . search . returnToSearch
41+
42+ if ( returnToPath ) {
43+ navigate ( {
44+ to : returnToPath ,
45+ search : returnToSearch ,
46+ } )
47+ } else {
48+ navigate ( { to : '/' } )
49+ }
50+ }
3851
3952 const moveSlide = ( step : number ) => {
4053 if ( images . length === 0 ) return
@@ -59,7 +72,7 @@ export default function PostDetail() {
5972
6073 return (
6174 < div
62- className = "fixed inset-0 z-[ 100] flex items-center justify-center bg-black/60"
75+ className = "fixed inset-0 z-100 flex items-center justify-center bg-black/60"
6376 onClick = { handleClose }
6477 >
6578 < svg width = "0" height = "0" className = "absolute" >
@@ -72,7 +85,7 @@ export default function PostDetail() {
7285
7386 < button
7487 onClick = { handleClose }
75- className = "absolute top-6 right-6 z-[ 110] text-white"
88+ className = "absolute top-6 right-6 z-110 text-white"
7689 >
7790 < X className = "h-10 w-10" />
7891 </ button >
@@ -91,7 +104,7 @@ export default function PostDetail() {
91104 { images . map ( ( img , idx ) => (
92105 < div
93106 key = { idx }
94- className = "flex h-full min-w-full flex- shrink-0 items-center justify-center"
107+ className = "flex h-full min-w-full shrink-0 items-center justify-center"
95108 >
96109 < img
97110 src = { img }
@@ -122,7 +135,7 @@ export default function PostDetail() {
122135 ease : 'easeInOut' ,
123136 } }
124137 onAnimationComplete = { ( ) => setIsAnimating ( false ) }
125- className = "pointer-events-none absolute z-[20] flex items-center justify-center"
138+ className = "pointer-events-none absolute z-20 flex items-center justify-center"
126139 >
127140 < Heart
128141 className = "h-32 w-32 drop-shadow-2xl"
0 commit comments