-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathCollectionGrid.tsx
More file actions
107 lines (104 loc) · 3.24 KB
/
CollectionGrid.tsx
File metadata and controls
107 lines (104 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import type { Ref } from 'react';
import React, { forwardRef } from 'react';
import classNames from 'classnames';
import type { PostCardProps } from '../common/common';
import { Container, generateTitleClamp } from '../common/common';
import FeedItemContainer from '../common/FeedItemContainer';
import { CollectionCardHeader } from './CollectionCardHeader';
import {
getPostClassNames,
FreeformCardTitle,
CardTextContainer,
} from '../common/Card';
import { WelcomePostCardFooter } from '../common/WelcomePostCardFooter';
import ActionButtons from '../common/ActionButtons';
import PostMetadata from '../common/PostMetadata';
import { usePostImage } from '../../../hooks/post/usePostImage';
import CardOverlay from '../common/CardOverlay';
import PostTags from '../common/PostTags';
import { isPostUpdated } from '../../../graphql/posts';
import { TimeFormatType } from '../../../lib/dateFormat';
export const CollectionGrid = forwardRef(function CollectionCard(
{
children,
post,
domProps = {},
onUpvoteClick,
onCommentClick,
onCopyLinkClick,
onPostClick,
onPostAuxClick,
onBookmarkClick,
onDownvoteClick,
onShare,
}: PostCardProps,
ref: Ref<HTMLElement>,
) {
const { pinnedAt, trending } = post;
const image = usePostImage(post);
const wasUpdated = isPostUpdated(post);
const onPostCardClick = () => onPostClick?.(post);
const onPostCardAuxClick = () => onPostAuxClick?.(post);
return (
<FeedItemContainer
domProps={{
...domProps,
className: getPostClassNames(
post,
domProps.className ?? '',
'min-h-card',
),
}}
ref={ref}
flagProps={{ pinnedAt, trending }}
bookmarked={post.bookmarked}
>
<CardOverlay
post={post}
onPostCardClick={onPostCardClick}
onPostCardAuxClick={onPostCardAuxClick}
/>
<CardTextContainer className="mx-4 flex-1">
<CollectionCardHeader post={post} />
<FreeformCardTitle
className={classNames(
generateTitleClamp({
hasImage: !!image,
hasHtmlContent: !!post.contentHtml,
}),
'font-bold text-text-primary typo-title3',
)}
>
{post.title}
</FreeformCardTitle>
<PostTags post={post} className="!items-end" />
</CardTextContainer>
<PostMetadata
createdAt={wasUpdated ? post.updatedAt : post.createdAt}
dateLabel={wasUpdated ? 'Updated' : undefined}
dateType={wasUpdated ? TimeFormatType.PostUpdated : TimeFormatType.Post}
readTime={post.readTime}
numSources={post.numCollectionSources}
className={classNames('mx-4', post.image ? 'my-0' : 'mb-4 mt-2')}
/>
<Container>
<WelcomePostCardFooter
image={image}
contentHtml={post.contentHtml}
post={post}
onShare={onShare}
/>
<ActionButtons
post={post}
onUpvoteClick={onUpvoteClick}
onCommentClick={onCommentClick}
onCopyLinkClick={onCopyLinkClick}
onBookmarkClick={onBookmarkClick}
className="mt-auto"
onDownvoteClick={onDownvoteClick}
/>
</Container>
{children}
</FeedItemContainer>
);
});