({ post, isExpanded = false, postIndex, setCommentMode })
| 19 | }; |
| 20 | |
| 21 | export function Post({ post, isExpanded = false, postIndex, setCommentMode }) { |
| 22 | const navigate = useNavigate(); |
| 23 | const { isAuthenticated } = AuthConsumer(); |
| 24 | const vidRef = useRef(null); |
| 25 | const inView = useInView(vidRef, { amount: "all" }); |
| 26 | const [modalShow, setShowModal] = useState(false); |
| 27 | const [modalData, setModalData] = useState(<></>); |
| 28 | useEffect(() => { |
| 29 | if (isExpanded) { |
| 30 | document.title = post.post_info.title; |
| 31 | } |
| 32 | return () => { |
| 33 | if (isExpanded) { |
| 34 | document.title = "Threaddit"; |
| 35 | } |
| 36 | } |
| 37 | }, [isExpanded]) |
| 38 | function onMediaClick(mediaType) { |
| 39 | if (post?.post_info.media) { |
| 40 | setShowModal(true); |
| 41 | if (mediaType === "video") { |
| 42 | setModalData(<ReactPlayer playing controls url={post?.post_info.media} />); |
| 43 | } else { |
| 44 | setModalData( |
| 45 | <img className="object-cover w-11/12 max-h-5/6 md:w-max md:max-h-screen" src={post?.post_info.media.replace("additional_args", "c_auto,g_auto")} alt="" /> |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | function onReplyClick() { |
| 51 | if (isAuthenticated) { |
| 52 | setCommentMode((data) => !data); |
| 53 | } else { |
| 54 | alert("You must be logged in to reply."); |
| 55 | } |
| 56 | } |
| 57 | const PostVariant = { |
| 58 | hidden: { |
| 59 | opacity: 0, |
| 60 | y: 100, |
| 61 | }, |
| 62 | animate: { |
| 63 | opacity: 1, |
| 64 | y: 0, |
| 65 | }, |
| 66 | empty: {}, |
| 67 | }; |
| 68 | function isImage(url) { |
| 69 | return /(jpg|jpeg|png|webp|avif|gif|svg|image)/.test(url); |
| 70 | } |
| 71 | async function handleShare() { |
| 72 | return navigator.clipboard |
| 73 | .writeText(`${location.host}/post/${post?.post_info.id}`) |
| 74 | .then(() => { |
| 75 | alert("Copied Post Link to clipboard"); |
| 76 | }) |
| 77 | .catch((err) => alert(err)); |
| 78 | } |
nothing calls this directly
no test coverage detected