-
Notifications
You must be signed in to change notification settings - Fork 42
/
article-list-item.web.js
139 lines (128 loc) · 3.47 KB
/
article-list-item.web.js
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
133
134
135
136
137
138
139
import React, { Fragment } from "react";
import ArticleSummary, {
ArticleSummaryHeadline,
ArticleSummaryContent
} from "@times-components/article-summary";
import Card from "@times-components/card";
import Context from "@times-components/context";
import Link from "@times-components/link";
import { Animations, colours } from "@times-components/styleguide";
import articleListItemTrackingEvents from "./article-list-item-tracking-events";
import { propTypes, defaultProps } from "./article-list-item-prop-types";
import { getImageUri, getHeadline } from "./utils";
import {
ListItemWrapper,
ListItemLongText,
ListItemShortText
} from "./styles/responsive";
const ArticleListItem = props => {
const {
article,
fadeImageIn,
highResSize,
imageRatio,
isLoading,
lowResSize,
showImage
} = props;
const {
bylines,
hasVideo,
headline,
label,
leadAsset,
longSummary,
publicationName,
publishedTime,
section,
shortHeadline,
shortSummary,
summary
} = article || {};
const imageUri = getImageUri(article);
const imageAccessibilityLabel = (leadAsset && leadAsset.caption) || "";
if (isLoading) {
return (
<ListItemWrapper>
<Card
contentContainerClass="articleListContent"
imageContainerClass="articleListImage"
imageRatio={imageRatio}
isLoading={isLoading}
showImage={showImage}
/>
</ListItemWrapper>
);
}
const childProps = {
bylineProps: bylines
? {
ast: bylines,
color: colours.section.default
}
: null,
datePublicationProps: {
date: publishedTime,
publication: publicationName
},
headline: (
<ArticleSummaryHeadline headline={getHeadline(headline, shortHeadline)} />
),
labelProps: {
color: colours.section[section] || colours.section.default,
isVideo: hasVideo,
title: label
}
};
const children = showImage ? (
<ArticleSummary
{...childProps}
content={<ArticleSummaryContent ast={summary} />}
/>
) : (
<Fragment>
<ListItemLongText>
<ArticleSummary
{...childProps}
content={<ArticleSummaryContent ast={longSummary} />}
/>
</ListItemLongText>
<ListItemShortText>
<ArticleSummary
{...childProps}
content={<ArticleSummaryContent ast={shortSummary} />}
/>
</ListItemShortText>
</Fragment>
);
return (
<Context.Consumer>
{({ makeArticleUrl }) => {
const canonicalUrl = makeArticleUrl(props.article);
return (
<Link url={canonicalUrl}>
<ListItemWrapper>
<Card
contentContainerClass="articleListContent"
fadeImageIn={fadeImageIn}
highResSize={highResSize}
imageAccessibilityLabel={imageAccessibilityLabel}
imageContainerClass="articleListImage"
imageRatio={imageRatio}
imageUri={imageUri}
isLoading={isLoading}
lowResSize={lowResSize}
showImage={showImage}
>
<Animations.FadeIn>{children}</Animations.FadeIn>
</Card>
</ListItemWrapper>
</Link>
);
}}
</Context.Consumer>
);
};
ArticleListItem.propTypes = propTypes;
ArticleListItem.defaultProps = defaultProps;
export default articleListItemTrackingEvents(ArticleListItem);