2023-11-15 16:15:44 +01:00
|
|
|
import { useRouter } from 'next/router'
|
2023-11-17 15:01:54 +01:00
|
|
|
import { HTMLAttributes, useEffect, useState } from 'react'
|
2023-11-15 16:15:44 +01:00
|
|
|
import { FaChevronLeft, FaX } from 'react-icons/fa6'
|
|
|
|
import Thread from './Thread'
|
2023-12-02 11:26:45 +01:00
|
|
|
import { Entity, MegalodonInterface } from 'megalodon'
|
2023-11-28 16:37:21 +01:00
|
|
|
import Reply from './Reply'
|
2023-12-02 03:50:42 +01:00
|
|
|
import Profile from './Profile'
|
2023-11-15 16:15:44 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
client: MegalodonInterface
|
2023-12-02 11:26:45 +01:00
|
|
|
openMedia: (media: Entity.Attachment) => void
|
2023-11-17 15:01:54 +01:00
|
|
|
} & HTMLAttributes<HTMLElement>
|
2023-11-15 16:15:44 +01:00
|
|
|
|
|
|
|
export default function Detail(props: Props) {
|
2023-12-02 03:50:42 +01:00
|
|
|
const [target, setTarget] = useState<'status' | 'reply' | 'profile' | null>(null)
|
2023-11-15 16:15:44 +01:00
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (router.query.status_id) {
|
|
|
|
setTarget('status')
|
2023-11-28 16:37:21 +01:00
|
|
|
} else if (router.query.reply_target_id) {
|
|
|
|
setTarget('reply')
|
2023-12-02 03:50:42 +01:00
|
|
|
} else if (router.query.user_id) {
|
|
|
|
setTarget('profile')
|
2023-11-15 16:15:44 +01:00
|
|
|
} else {
|
|
|
|
setTarget(null)
|
|
|
|
}
|
|
|
|
}, [router.query])
|
|
|
|
|
|
|
|
const back = () => {
|
|
|
|
router.back()
|
|
|
|
}
|
|
|
|
|
|
|
|
const close = () => {
|
|
|
|
router.push({ query: { id: router.query.id, timeline: router.query.timeline } })
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{target && (
|
2023-11-17 15:01:54 +01:00
|
|
|
<div className={`bg-white ${props.className}`} style={props.style}>
|
2023-11-15 16:15:44 +01:00
|
|
|
<div className="bg-blue-900 text-gray-200 flex justify-between p-2 items-center" style={{ height: '50px' }}>
|
|
|
|
<FaChevronLeft onClick={back} className="cursor-pointer text-lg" />
|
|
|
|
<FaX onClick={close} className="cursor-pointer text-lg" />
|
|
|
|
</div>
|
2023-12-02 11:26:45 +01:00
|
|
|
{target === 'status' && <Thread client={props.client} status_id={router.query.status_id as string} openMedia={props.openMedia} />}
|
|
|
|
{target === 'reply' && (
|
|
|
|
<Reply client={props.client} status_id={router.query.reply_target_id as string} openMedia={props.openMedia} />
|
|
|
|
)}
|
|
|
|
{target === 'profile' && <Profile client={props.client} user_id={router.query.user_id as string} openMedia={props.openMedia} />}
|
2023-11-15 16:15:44 +01:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|