-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathPostCardHeader.tsx
More file actions
132 lines (125 loc) · 4.18 KB
/
PostCardHeader.tsx
File metadata and controls
132 lines (125 loc) · 4.18 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import type { ReactElement, ReactNode } from 'react';
import React from 'react';
import classNames from 'classnames';
import dynamic from 'next/dynamic';
import { CardHeader } from './ListCard';
import { ReadArticleButton } from '../ReadArticleButton';
import { getGroupedHoverContainer } from '../common';
import { useBookmarkProvider, useFeedPreviewMode } from '../../../../hooks';
import type { Post } from '../../../../graphql/posts';
import { PostType } from '../../../../graphql/posts';
import { ButtonVariant } from '../../../buttons/common';
import type { PostMetadataProps } from './PostMetadata';
import PostMetadata from './PostMetadata';
import { OpenLinkIcon } from '../../../icons';
import { useReadPostButtonText } from './hooks';
import { BookmakProviderHeader } from './BookmarkProviderHeader';
import { ProfileImageSize } from '../../../ProfilePicture';
import { ProfileImageLink } from '../../../profile/ProfileImageLink';
import type { UserShortProfile } from '../../../../lib/user';
import { PostOptionButton } from '../../../../features/posts/PostOptionButton';
import { isSourceUserSource } from '../../../../graphql/sources';
const HoverCard = dynamic(
/* webpackChunkName: "hoverCard" */ () => import('../HoverCard'),
);
const UserEntityCard = dynamic(
/* webpackChunkName: "userEntityCard" */ () =>
import('../../entity/UserEntityCard'),
);
interface CardHeaderProps {
post: Post;
className?: string;
children?: ReactNode;
onReadArticleClick?: (e: React.MouseEvent) => unknown;
postLink?: string;
openNewTab?: boolean;
readButtonContent?: string;
readButtonIcon?: ReactElement;
metadata?: {
topLabel?: PostMetadataProps['topLabel'];
bottomLabel?: PostMetadataProps['bottomLabel'];
dateFirst?: PostMetadataProps['dateFirst'];
};
}
const Container = getGroupedHoverContainer('span');
export const PostCardHeader = ({
post,
className,
onReadArticleClick,
children,
postLink,
openNewTab,
readButtonContent,
readButtonIcon,
metadata,
}: CardHeaderProps): ReactElement => {
const isFeedPreview = useFeedPreviewMode();
const postButtonText = useReadPostButtonText(post);
const { highlightBookmarkedPost } = useBookmarkProvider({
bookmarked: post.bookmarked ?? false,
});
const isCollectionType = post.type === 'collection';
const isUserSource = isSourceUserSource(post.source);
const showCTA =
!isFeedPreview &&
([PostType.Article, PostType.VideoYouTube].includes(post.type) ||
!!readButtonContent);
return (
<>
{highlightBookmarkedPost && <BookmakProviderHeader className="mb-4" />}
<CardHeader className={className}>
{children}
{!!post?.author && (
<HoverCard
align="start"
side="bottom"
sideOffset={10}
trigger={
<ProfileImageLink
className={classNames('z-1', !!children && 'ml-2')}
picture={{
size: isUserSource
? ProfileImageSize.Large
: ProfileImageSize.Medium,
}}
user={post.author}
/>
}
>
<UserEntityCard user={post.author as UserShortProfile} />
</HoverCard>
)}
<PostMetadata
className={classNames(
'mr-2 flex-1',
!isCollectionType && 'ml-4',
isCollectionType && 'ml-2',
)}
createdAt={post.createdAt}
{...metadata}
/>
<Container
className="relative ml-auto flex flex-row"
data-testid="cardHeaderActions"
>
{!isFeedPreview && (
<>
{showCTA && (
<ReadArticleButton
content={readButtonContent ?? postButtonText ?? ''}
className="mr-2"
variant={ButtonVariant.Tertiary}
icon={readButtonIcon ?? <OpenLinkIcon />}
href={postLink ?? ''}
onClick={onReadArticleClick}
openNewTab={openNewTab}
/>
)}
<PostOptionButton post={post} />
</>
)}
</Container>
</CardHeader>
</>
);
};