2023-09-11 00:40:14 -05:00
|
|
|
import { Text } from '@codemirror/state';
|
|
|
|
|
import Image from 'next/image';
|
2023-09-11 13:44:51 -05:00
|
|
|
import { Doc, Id } from '../../convex/_generated/dataModel';
|
2023-09-11 00:40:14 -05:00
|
|
|
import PostContent from './PostContent';
|
|
|
|
|
|
2023-09-11 13:44:51 -05:00
|
|
|
export default function Post({
|
|
|
|
|
post,
|
|
|
|
|
}: {
|
|
|
|
|
post: Doc<'posts'> & {
|
|
|
|
|
user: {
|
|
|
|
|
_id: Id<'users'>;
|
|
|
|
|
_creationTime: number;
|
|
|
|
|
clerkUsername: string | null;
|
|
|
|
|
clerkImageUrl: string;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}) {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='flex w-full h-full gap-4 p-8 bg-white dark:bg-secondary-gray border border-gray-600'>
|
|
|
|
|
<div>
|
|
|
|
|
<Image
|
|
|
|
|
alt='user profile image'
|
2023-09-11 13:44:51 -05:00
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|