All files / web/modules/article/list ArticleList.tsx

52.17% Statements 12/23
0% Branches 0/2
0% Functions 0/4
70.59% Lines 12/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 601x 1x   1x 1x 1x 1x 1x 1x 1x                       1x                 1x                                                       1x  
import * as React from 'react';
import { Query } from 'react-apollo';
import { IArticle } from '../../../../shared';
import Empty from '../../components/Empty';
import ErrorMessage from '../../components/ErrorMessage';
import Helmet from '../../components/Helmet';
import Loader from '../../components/Loader';
import LoadMoreContainer from '../../components/LoadMoreContainer';
import { ARTICLES, CATEGORY } from '../queries';
import ListItem from './ListItem';
 
interface IListProps {
  dataSource: {
    articles: IArticle[];
  };
}
 
interface IProps {
  slug: string;
}
 
const List = ({ dataSource }: IListProps) => (
  <div>
    {!dataSource.articles.length && <Empty />}
    {dataSource.articles.map((article: IArticle) => (
      <ListItem key={article._id} {...article} />
    ))}
  </div>
);
 
const ArticleList = ({ slug }: IProps) => (
  <Query query={CATEGORY} variables={{ slug }}>
    {({ loading, error, data }) => {
      if (error) {
        return <ErrorMessage message={error.message} />;
      }
 
      if (loading) {
        return <Loader />;
      }
 
      return (
        <React.Fragment>
          <Helmet title={data.category.title} />
          <LoadMoreContainer
            size={data.articleCount}
            listComponent={List}
            query={ARTICLES}
            queryVariables={{
              categorySlug: slug,
            }}
          />
        </React.Fragment>
      );
    }}
  </Query>
);
 
export default ArticleList;