-
Notifications
You must be signed in to change notification settings - Fork 42
/
article-magazine-standard.js
146 lines (135 loc) · 4.29 KB
/
article-magazine-standard.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
140
141
142
143
144
145
146
/* eslint-disable consistent-return */
import React, { Component, Fragment } from "react";
import ArticleError from "@times-components/article-error";
import ArticleSkeleton from "@times-components/article-skeleton";
import {
getHeadline,
getLeadAsset,
getStandardTemplateCrop
} from "@times-components/utils";
import { CentredCaption } from "@times-components/caption";
import { ResponsiveContext } from "@times-components/responsive";
import { tabletWidth } from "@times-components/styleguide";
import LeadAsset from "@times-components/article-lead-asset";
import Context from "@times-components/context";
import ArticleHeader from "./article-header/article-header";
import {
articlePropTypes,
articleDefaultProps
} from "./article-prop-types/article-prop-types";
import styles from "./styles";
class ArticleMagazineStandard extends Component {
constructor(props) {
super(props);
this.renderHeader = this.renderHeader.bind(this);
}
renderHeader({ width }) {
const { article, onAuthorPress, onImagePress, onVideoPress } = this.props;
const {
bylines,
expirableFlags,
hasVideo,
headline,
label,
publicationName,
publishedTime,
shortHeadline,
standfirst
} = article;
return (
<ResponsiveContext.Consumer>
{({ isTablet }) => (
<Fragment>
<ArticleHeader
bylines={bylines}
flags={expirableFlags}
hasVideo={hasVideo}
headline={getHeadline(headline, shortHeadline)}
isTablet={isTablet}
label={label}
onAuthorPress={onAuthorPress}
publicationName={publicationName}
publishedTime={publishedTime}
standfirst={standfirst}
/>
<LeadAsset
{...getLeadAsset(article)}
getImageCrop={getStandardTemplateCrop}
onImagePress={onImagePress}
onVideoPress={onVideoPress}
renderCaption={({ caption }) => <CentredCaption {...caption} />}
style={[
styles.leadAssetContainer,
isTablet && styles.leadAssetContainerTablet,
isTablet && styles.tabletContainer
]}
width={Math.min(width, tabletWidth)}
/>
</Fragment>
)}
</ResponsiveContext.Consumer>
);
}
render() {
const { error, refetch, isLoading } = this.props;
if (error) {
return <ArticleError refetch={refetch} />;
}
if (isLoading) {
return null;
}
const {
adConfig,
analyticsStream,
article,
interactiveConfig,
onAuthorPress,
onCommentGuidelinesPress,
onCommentsPress,
onImagePress,
onLinkPress,
onRelatedArticlePress,
onTopicPress,
onTwitterLinkPress,
onVideoPress,
onViewed,
receiveChildList
} = this.props;
return (
<ResponsiveContext.Consumer>
{({ isTablet }) => (
<Context.Consumer>
{({ theme: { scale, dropCapFont } }) => (
<ArticleSkeleton
adConfig={adConfig}
analyticsStream={analyticsStream}
data={article}
dropCapFont={dropCapFont}
Header={this.renderHeader}
interactiveConfig={interactiveConfig}
isTablet={isTablet}
onAuthorPress={onAuthorPress}
onCommentGuidelinesPress={onCommentGuidelinesPress}
onCommentsPress={onCommentsPress}
onImagePress={onImagePress}
onLinkPress={onLinkPress}
onRelatedArticlePress={onRelatedArticlePress}
onTopicPress={onTopicPress}
onTwitterLinkPress={onTwitterLinkPress}
onVideoPress={onVideoPress}
onViewableItemsChanged={
onViewed ? this.onViewableItemsChanged : null
}
receiveChildList={receiveChildList}
scale={scale}
/>
)}
</Context.Consumer>
)}
</ResponsiveContext.Consumer>
);
}
}
ArticleMagazineStandard.propTypes = articlePropTypes;
ArticleMagazineStandard.defaultProps = articleDefaultProps;
export default ArticleMagazineStandard;