docbrown/app/javascript/articles/Article.jsx
Josh Puetz 2abe830377
[deploy] Home Page Feed redesign + top comments (#7579)
* feed cards

* frontend

* preactify

* preactify

* .

* fix

* fixing things and adding dropdown

* whoops.

* whoops 2.

* revert body bg color change

* search snippet

* search snippet

* get rid of featured article

* get rid of featured article...

* cover to its own component

* videos

* videos

* reading time

* small-save-filled asset

* author adjustments

* adjustments

* Author --> Meta

* whoops.

* loader

* logged out state

* .

* dropping what's not needed for now

* better name for cover

* get rid of nav overflow

* bringin comments placeholder back

* bringing comments placeholder back

* publish date

* fix

* date

* .

* save button icon

* ghost button

* lets skip the icon for saving for now

* more buttons

* counting logic

* Display top comments on homepage feed

* Comment list and item components

* Remove 'Top Comments' title

* Remove subscribe button, add reading time

* Update snapshots and tests

* Fix article and follower scrolling

* Added reading time

* (Try) to do flare tags

* Button component from Pawel

* More button styles from Pawel

* Comment count style from Pawel

* Handle empty parens for age on older articles

* Dont show 'more comment' button for more than 2 comments

* cover ratio

* flare tag

* cover fix

* fix buttons

* more button fixes

* tags fix

* responsiveness fix

* reading time  + a bit of responsiveness

* Reading time in more places

* snapshots

* default color for flare tag

* Update CommentsList test snapshot with new styles

* fixing search results

* fixing buttons

* Fix podcast card tests by updating snapshots

* Line clamping for top comments

* Reflect save button state after click before mouseout

* Now the entire feed card is clickable. (#7638)

* Now pointer cursor is only on feed posts. (#7727)

* Revert podcast card styling

* Update test snapshot

* merge

* Fix rspec on feed page

* Reduce complexity of class check for feed card clicking

* PR feedback/fixes

* Fix featured article test and snapshot

* Last minute test tweaks

* clean up crayons

* padding issue + empty div

* Correct merge error

* Fix search results tests

* Test fixes and snapshot updates

* themes

* podcasts colors

Co-authored-by: ludwiczakpawel <ludwiczakpawel@gmail.com>
Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
2020-05-12 07:57:57 -05:00

122 lines
3.3 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
import { articlePropTypes } from '../src/components/common-prop-types/article-prop-types';
import {
ArticleCoverImage,
CommentsCount,
CommentsList,
ContentTitle,
Meta,
SaveButton,
SearchSnippet,
TagList,
ReactionsCount,
ReadingTime,
Video,
} from './components';
import { PodcastArticle } from './PodcastArticle';
export const Article = ({
article,
isFeatured,
isBookmarked,
bookmarkClick,
}) => {
if (article && article.type_of === 'podcast_episodes') {
return <PodcastArticle article={article} />;
}
const clickableClassList = [
'crayons-story',
'crayons-story__top',
'crayons-story__body',
'crayons-story__indention',
'crayons-story__title',
'crayons-story__tags',
'crayons-story__bottom',
];
return (
<article
className={`crayons-story cursor-pointer ${
isFeatured && 'crayons-story--featured'
}`}
id={isFeatured && 'featured-story-marker'}
data-featured-article={isFeatured && `articles-${article.id}`}
data-content-user-id={article.user_id}
>
<div
role="presentation"
onClick={(event) => {
const { classList } = event.target;
if (clickableClassList.includes(...classList)) {
InstantClick.preload(article.path);
InstantClick.display(article.path);
}
}}
>
{article.cloudinary_video_url && <Video article={article} />}
{isFeatured && <ArticleCoverImage article={article} />}
<div className="crayons-story__body">
<div className="crayons-story__top">
<Meta article={article} organization={article.organization} />
</div>
<div className="crayons-story__indention">
<ContentTitle article={article} />
<TagList tags={article.tag_list} />
{article.class_name === 'Article' && (
// eslint-disable-next-line no-underscore-dangle
<SearchSnippet highlightText={article.highlight} />
)}
<div className="crayons-story__bottom">
{article.class_name !== 'User' && (
<div className="crayons-story__details">
<ReactionsCount article={article} />
<CommentsCount
count={article.comments_count}
articlePath={article.path}
/>
</div>
)}
<div className="crayons-story__save">
<ReadingTime readingTime={article.reading_time} />
<SaveButton
article={article}
isBookmarked={isBookmarked}
onClick={bookmarkClick}
/>
</div>
</div>
</div>
</div>
{article.top_comments && article.top_comments.length > 0 && (
<CommentsList
comments={article.top_comments}
articlePath={article.path}
totalCount={article.comments_count}
/>
)}
</div>
</article>
);
};
Article.defaultProps = {
isBookmarked: false,
isFeatured: false,
};
Article.propTypes = {
article: articlePropTypes.isRequired,
isBookmarked: PropTypes.bool,
isFeatured: PropTypes.bool,
bookmarkClick: PropTypes.func.isRequired,
};