2023-09-14 21:47:40 -05:00
|
|
|
import { PostWithUserDto } from '@/app/types';
|
|
|
|
|
import { useUser } from '@clerk/nextjs';
|
|
|
|
|
import { Text } from '@codemirror/state';
|
|
|
|
|
import Image from 'next/image';
|
2023-09-15 13:26:19 -05:00
|
|
|
import Link from 'next/link';
|
2023-09-14 21:47:40 -05:00
|
|
|
import PostActionButton from './PostActionButtons';
|
|
|
|
|
import PostActionModal from './PostActionModal';
|
|
|
|
|
import PostContent from './PostContent';
|
|
|
|
|
|
|
|
|
|
export default function Reply({ post }: { post: PostWithUserDto }) {
|
|
|
|
|
const { user, isSignedIn, isLoaded } = useUser();
|
|
|
|
|
const username = post.user.clerkUsername ?? post.user._id;
|
|
|
|
|
const created = new Date(post._creationTime);
|
|
|
|
|
const month = created.toLocaleString(undefined, { month: 'short' });
|
|
|
|
|
const day = created.getDate();
|
|
|
|
|
const year = created.getFullYear();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='flex w-full gap-4'>
|
|
|
|
|
<div>
|
2023-09-15 13:26:19 -05:00
|
|
|
<Link href={`/profile/${post.user.clerkUserId}`}>
|
|
|
|
|
<Image
|
|
|
|
|
alt='user profile image'
|
|
|
|
|
src={post.user.clerkImageUrl}
|
|
|
|
|
width={40}
|
|
|
|
|
height={40}
|
|
|
|
|
className='rounded-full object-cover border-4 border-primary-accent'
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
2023-09-14 21:47:40 -05:00
|
|
|
</div>
|
|
|
|
|
<div className='flex flex-col flex-1 w-full border border-gray-600 rounded-md'>
|
|
|
|
|
<div className='flex flex-col w-full p-1'>
|
2023-09-14 23:02:47 -05:00
|
|
|
<div className='flex justify-between dark:bg-primary-gray p-2'>
|
2023-09-14 21:47:40 -05:00
|
|
|
<div className='text-sm'>
|
|
|
|
|
{`${username} `}
|
|
|
|
|
<span className='text-[#7a838f]'>{`replied on ${month} ${day}, ${year}`}</span>
|
|
|
|
|
</div>
|
|
|
|
|
{isLoaded && isSignedIn && user.id === post.user.clerkUserId ? (
|
|
|
|
|
<PostActionModal postId={post._id} />
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
<div className='p-1'>
|
2023-09-14 23:02:47 -05:00
|
|
|
<div className='p-2 rounded-md dark:bg-secondary-gray'>
|
2023-09-14 21:47:40 -05:00
|
|
|
<PostContent content={Text.of(post.content).toString()} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='p-1'>
|
|
|
|
|
<PostActionButton
|
|
|
|
|
postId={post._id}
|
|
|
|
|
showReply={false}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|