Files
conve-x/src/components/Post.tsx
T

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-11 13:51:35 -05:00
import { PostWithUserDto } from '@/app/types';
2023-09-11 00:40:14 -05:00
import { Text } from '@codemirror/state';
import Image from 'next/image';
import PostContent from './PostContent';
2023-09-11 13:49:13 -05:00
export default function Post({ post }: { post: PostWithUserDto }) {
const username = post.user.clerkUsername ?? post.user._id;
2023-09-11 00:40:14 -05:00
const createdPostDate = new Date(post._creationTime);
const postYear = createdPostDate.getFullYear();
const postMonth = createdPostDate.toLocaleString(undefined, {
month: 'short',
});
const dayOfMonth = createdPostDate.getDate();
2023-09-11 13:51:35 -05:00
// TODO: Posts content should only be allowed to grow to a set height
// after which the post's content should be truncated
// and we should display a 'more' link to load the post
// in an individual page
// TODO: Add menu button
// TODO: Add reply and like buttons
2023-09-11 00:40:14 -05:00
return (
<div className='flex w-full h-full gap-4 p-8 bg-white dark:bg-secondary-gray'>
2023-09-11 00:40:14 -05:00
<div>
<Image
alt='user profile image'
src={post.user.clerkImageUrl}
2023-09-11 00:40:14 -05:00
width={40}
height={40}
className='rounded-full object-cover border-4 border-primary-accent'
/>
</div>
<div className='flex flex-col gap-2'>
<div className='flex items-center gap-2'>
<div>{username}</div>
<div className='text-xs'>{`${postMonth} ${dayOfMonth}, ${postYear}`}</div>
</div>
<div>
<PostContent content={Text.of(post.content).toString()} />
</div>
<div></div>
</div>
</div>
);
}