'use client'; import { PostWithUserDto } from '@/app/types'; import { useUser } from '@clerk/nextjs'; import { Text } from '@codemirror/state'; import { useMutation } from 'convex/react'; import Image from 'next/image'; import Link from 'next/link'; import { GoDotFill } from 'react-icons/go'; import { api } from '../../convex/_generated/api'; import PostActionButton from './PostActionButtons'; import PostActionModal from './PostActionModal'; import PostContent from './PostContent'; export default function Post({ post, limit = true, showReply = true, }: { post: PostWithUserDto; limit?: boolean; showReply?: boolean; }) { const { isLoaded, user, isSignedIn } = useUser(); const deletePostById = useMutation(api.posts.deletePostById); const username = post.user.clerkUsername ?? post.user._id; const createdPostDate = new Date(post._creationTime); const postYear = createdPostDate.getFullYear(); const postMonth = createdPostDate.toLocaleString(undefined, { month: 'short', }); const dayOfMonth = createdPostDate.getDate(); const content = limit ? post.content.slice(0, 10) : post.content; const postLink = `/posts/${post._id}`; async function handleDeleteClick() { const result = confirm('Are you sure you want to delete this post?'); if (result === false) { return; } await deletePostById({ id: post._id }); } return (
user profile image
{username}
{`${postMonth} ${dayOfMonth}, ${postYear}`}
{isLoaded && isSignedIn && user.id === post.user.clerkUserId ? ( ) : null}
{limit && post.content.length > 10 ? ( Show more ) : null}
); }