({
posts,
isLoading,
className,
title = 'You might like',
moreButtonProps,
ListItem = DefaultListItem,
}: SimilarPostsProps)
| 107 | DefaultListItem.Placeholder = DefaultListItemPlaceholder; |
| 108 | |
| 109 | export default function SimilarPosts({ |
| 110 | posts, |
| 111 | isLoading, |
| 112 | className, |
| 113 | title = 'You might like', |
| 114 | moreButtonProps, |
| 115 | ListItem = DefaultListItem, |
| 116 | }: SimilarPostsProps): ReactElement { |
| 117 | const { logEvent } = useLogContext(); |
| 118 | const { logOpts } = useContext(ActiveFeedContext); |
| 119 | const moreButtonHref = |
| 120 | moreButtonProps?.href ?? process.env.NEXT_PUBLIC_WEBAPP_URL ?? '/'; |
| 121 | const moreButtonText = moreButtonProps?.text || 'View all'; |
| 122 | const displayPosts = posts ?? []; |
| 123 | |
| 124 | const onLinkClick = async (post: Post): Promise<void> => { |
| 125 | logEvent( |
| 126 | postLogEvent(LogEvent.Click, post, { |
| 127 | extra: { origin: 'recommendation' }, |
| 128 | ...(logOpts && logOpts), |
| 129 | }), |
| 130 | ); |
| 131 | }; |
| 132 | |
| 133 | return ( |
| 134 | <WidgetContainer |
| 135 | className={classNames('flex flex-col overflow-hidden p-4', className)} |
| 136 | > |
| 137 | <h4 className="mb-2 font-bold text-text-primary typo-callout">{title}</h4> |
| 138 | {isLoading ? ( |
| 139 | <> |
| 140 | <ListItem.Placeholder /> |
| 141 | <ListItem.Placeholder /> |
| 142 | <ListItem.Placeholder /> |
| 143 | </> |
| 144 | ) : ( |
| 145 | <> |
| 146 | {displayPosts.map((post) => ( |
| 147 | <ListItem |
| 148 | key={post.id} |
| 149 | post={post} |
| 150 | onLinkClick={() => onLinkClick(post)} |
| 151 | /> |
| 152 | ))} |
| 153 | </> |
| 154 | )} |
| 155 | <Link href={moreButtonHref} passHref> |
| 156 | <Button |
| 157 | variant={ButtonVariant.Tertiary} |
| 158 | className="mt-2 self-start" |
| 159 | size={ButtonSize.Small} |
| 160 | tag="a" |
| 161 | icon={<ArrowIcon className="rotate-90" />} |
| 162 | iconPosition={ButtonIconPosition.Right} |
| 163 | > |
| 164 | {moreButtonText} |
| 165 | </Button> |
| 166 | </Link> |
nothing calls this directly
no test coverage detected