2022-10-02 23:02:31 +00:00
|
|
|
import { track } from '@amplitude/analytics-browser'
|
2022-10-05 10:37:23 +00:00
|
|
|
import { DocumentIcon } from '@heroicons/react/solid'
|
2022-10-02 23:02:31 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { Post } from 'common/post'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { postPath } from 'web/lib/firebase/posts'
|
|
|
|
import { fromNow } from 'web/lib/util/time'
|
|
|
|
import { Avatar } from './avatar'
|
2022-10-06 01:02:24 +00:00
|
|
|
import { Card } from './card'
|
2022-10-02 23:02:31 +00:00
|
|
|
import { CardHighlightOptions } from './contract/contracts-grid'
|
2022-10-12 16:21:58 +00:00
|
|
|
import { Row } from './layout/row'
|
2022-10-02 23:02:31 +00:00
|
|
|
import { UserLink } from './user-link'
|
|
|
|
|
|
|
|
export function PostCard(props: {
|
|
|
|
post: Post
|
|
|
|
onPostClick?: (post: Post) => void
|
|
|
|
highlightOptions?: CardHighlightOptions
|
|
|
|
}) {
|
|
|
|
const { post, onPostClick, highlightOptions } = props
|
|
|
|
const { itemIds: itemIds, highlightClassName } = highlightOptions || {}
|
|
|
|
|
|
|
|
return (
|
2022-10-12 16:21:58 +00:00
|
|
|
<Card
|
|
|
|
className={clsx(
|
|
|
|
'group relative flex gap-3 py-2 px-3',
|
|
|
|
itemIds?.includes(post.id) && highlightClassName
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Row className="flex grow justify-between">
|
2022-10-02 23:02:31 +00:00
|
|
|
<div className="">
|
2022-10-12 16:21:58 +00:00
|
|
|
<Row className="items-center text-sm ">
|
2022-10-12 16:31:00 +00:00
|
|
|
<Avatar
|
|
|
|
className="mx-1 h-7 w-7"
|
|
|
|
username={post.creatorUsername}
|
|
|
|
avatarUrl={post.creatorAvatarUrl}
|
|
|
|
/>
|
2022-10-02 23:02:31 +00:00
|
|
|
<UserLink
|
2022-10-12 16:21:58 +00:00
|
|
|
className=" text-gray-400"
|
2022-10-12 15:42:28 +00:00
|
|
|
name={post.creatorName}
|
|
|
|
username={post.creatorUsername}
|
2022-10-02 23:02:31 +00:00
|
|
|
/>
|
2022-10-12 16:21:58 +00:00
|
|
|
<span className="mx-1 text-gray-400">•</span>
|
|
|
|
<span className="text-gray-400">{fromNow(post.createdTime)}</span>
|
|
|
|
</Row>
|
|
|
|
<div className=" break-words text-lg font-semibold text-indigo-700 group-hover:underline group-hover:decoration-indigo-400 group-hover:decoration-2">
|
2022-10-05 10:37:23 +00:00
|
|
|
{post.title}
|
|
|
|
</div>
|
2022-10-12 16:21:58 +00:00
|
|
|
<div className="font-small text-md break-words text-indigo-400">
|
2022-10-05 10:37:23 +00:00
|
|
|
{post.subtitle}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span className="inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-indigo-300 px-2 py-0.5 text-xs font-medium text-white">
|
|
|
|
<DocumentIcon className={'h3 w-3'} />
|
|
|
|
Post
|
|
|
|
</span>
|
2022-10-02 23:02:31 +00:00
|
|
|
</div>
|
2022-10-12 16:21:58 +00:00
|
|
|
</Row>
|
2022-10-02 23:02:31 +00:00
|
|
|
{onPostClick ? (
|
|
|
|
<a
|
|
|
|
className="absolute top-0 left-0 right-0 bottom-0"
|
|
|
|
onClick={(e) => {
|
|
|
|
// Let the browser handle the link click (opens in new tab).
|
|
|
|
if (e.ctrlKey || e.metaKey) return
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
track('select post card'),
|
|
|
|
{
|
|
|
|
slug: post.slug,
|
|
|
|
postId: post.id,
|
|
|
|
}
|
|
|
|
onPostClick(post)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Link href={postPath(post.slug)}>
|
|
|
|
<a
|
|
|
|
onClick={() => {
|
|
|
|
track('select post card'),
|
|
|
|
{
|
|
|
|
slug: post.slug,
|
|
|
|
postId: post.id,
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="absolute top-0 left-0 right-0 bottom-0"
|
|
|
|
/>
|
|
|
|
</Link>
|
|
|
|
)}
|
2022-10-12 16:21:58 +00:00
|
|
|
</Card>
|
2022-10-02 23:02:31 +00:00
|
|
|
)
|
|
|
|
}
|
2022-10-05 10:37:23 +00:00
|
|
|
|
|
|
|
export function PostCardList(props: {
|
|
|
|
posts: Post[]
|
|
|
|
highlightOptions?: CardHighlightOptions
|
|
|
|
onPostClick?: (post: Post) => void
|
|
|
|
}) {
|
|
|
|
const { posts, onPostClick, highlightOptions } = props
|
|
|
|
return (
|
|
|
|
<div className="w-full">
|
|
|
|
{posts.map((post) => (
|
|
|
|
<PostCard
|
|
|
|
key={post.id}
|
|
|
|
post={post}
|
|
|
|
onPostClick={onPostClick}
|
|
|
|
highlightOptions={highlightOptions}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|