docbrown/app/javascript/articles/Article.jsx
Nick Taylor 5e677daac1
Homepage feed components (#6052)
* wip - <PodcastArticle /> component.

* Added filler user avatar for other article types.

* Added <LoadingArticle /> component.

* wip

* wip on <Article /> component.

* Added <Article /> component to barrel file.

* Deleted assets from dummy storybook assets folder.

* Updated podcast article story avatar.

* More work on <Article /> component.

* Refactoring Storybook stories.

* Refactored so main component is just the <Article /> component.

* Added a missing video article property.

* Some refactoring of <Article /> component.

* Added Storybook knobs addon.

* Now <Article /> component supports an isBookmarked prop.

* Fixed podcast Storybook story.

* Made the knobs Storybook addon the first tab

* Added more <Article /> Storybook stories.

* More <Article /> component tweaks.

* Added publish time to <Article /> component stories.

* Made the timeAgo function compatible with Preact.

* Added loading="lazy" attribute to <img /> in <Article /> component.

* Added <Article /> Storybook story for past published date.

* Fixed publish date for <Article /> story data.

* Scrapped random avatars.

* Added snapshots for <Article /> component.

* Added snapshots for <LoadingArticle /> component.

* Now test article entities are shared.

* Fixed some wording of Storybook stories.

* Breaking up Article.jsx to make codeclimate happy.

* Now <Article /> component receives icon props.

* Added knobs for <Article /> icon props.

* Added *.stories.jsx to codeclimate exclusion list.

* Added **/*.stories.jsx to codeclimate exclusion list.

* Alright now we have the good glob for excluding Storybook from codeclimate 😆

* Added org headline changes from low hanging fruit PR.

* Updated <Article /> snapshot for org headline.
2020-02-19 11:39:13 -06:00

136 lines
3.8 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
import { articlePropTypes } from '../src/components/common-prop-types/article-prop-types';
import {
CommentsCount,
ContentTitle,
OrganizationHeadline,
PublishDate,
ReadingTime,
SaveButton,
SearchSnippet,
TagList,
ReactionsCount,
} from './components';
import { PodcastArticle } from './PodcastArticle';
/* global timeAgo */
export const Article = ({
article,
currentTag,
isBookmarked,
reactionsIcon,
commentsIcon,
videoIcon,
}) => {
if (article && article.type_of === 'podcast_episodes') {
return <PodcastArticle article={article} />;
}
return (
<div
className="single-article single-article-small-pic"
data-content-user-id={article.user_id}
>
{article.cloudinary_video_url && (
<a
href={article.path}
className="single-article-video-preview"
style={`background-image:url(${article.cloudinary_video_url})`}
>
<div className="single-article-video-duration">
<img src={videoIcon} alt="video camera" loading="lazy" />
{article.video_duration_in_minutes}
</div>
</a>
)}
<OrganizationHeadline organization={article.organization} />
<div className="small-pic">
<a
href={`/${article.user.username}`}
className="small-pic-link-wrapper"
>
<img
src={article.user.profile_image_90}
alt={`${article.user.username} profile`}
loading="lazy"
/>
</a>
</div>
<a
href={article.path}
className="small-pic-link-wrapper index-article-link"
id={`article-link-${article.id}`}
>
<div className="content">
<ContentTitle article={article} currentTag={currentTag} />
{article.class_name === 'Article' && (
// eslint-disable-next-line no-underscore-dangle
<SearchSnippet snippetResult={article._snippetResult} />
)}
</div>
</a>
<h4>
<a href={`/${article.user.username}`}>
{filterXSS(
article.class_name === 'User'
? article.user.username
: article.user.name,
)}
{article.readable_publish_date ? '・' : ''}
{article.readable_publish_date && (
<PublishDate
readablePublishDate={article.readable_publish_date}
publishedTimestamp={article.published_timestamp}
/>
)}
{article.published_at_int ? (
<span className="time-ago-indicator">
(
{timeAgo({
oldTimeInSeconds: article.published_at_int,
formatter: x => x,
})}
)
</span>
) : null}
</a>
</h4>
<TagList tags={article.tag_list || article.cached_tag_list_array} />
{article.class_name !== 'User' && (
<CommentsCount
count={article.comments_count}
articlePath={article.path}
icon={commentsIcon}
/>
)}
{article.class_name !== 'User' && (
<ReactionsCount article={article} icon={reactionsIcon} />
)}
{article.class_name === 'Article' && (
<ReadingTime
articlePath={article.path}
readingTime={article.reading_time}
/>
)}
<SaveButton article={article} isBookmarked={isBookmarked} />
</div>
);
};
Article.defaultProps = {
currentTag: null,
isBookmarked: false,
};
Article.propTypes = {
article: articlePropTypes.isRequired,
currentTag: PropTypes.string,
isBookmarked: PropTypes.bool,
reactionsIcon: PropTypes.string.isRequired,
commentsIcon: PropTypes.string.isRequired,
videoIcon: PropTypes.string.isRequired,
};