-
Notifications
You must be signed in to change notification settings - Fork 42
/
article-in-depth.js
160 lines (150 loc) · 4.69 KB
/
article-in-depth.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* eslint-disable consistent-return */
import React, { Component, Fragment } from "react";
import { View } from "react-native";
import ArticleError from "@times-components/article-error";
import ArticleSkeleton from "@times-components/article-skeleton";
import ArticleLeadAsset from "@times-components/article-lead-asset";
import { CentredCaption } from "@times-components/caption";
import { ResponsiveContext } from "@times-components/responsive";
import {
getHeadline,
getLeadAsset,
getStandardTemplateCrop
} from "@times-components/utils";
import Context from "@times-components/context";
import ArticleHeader from "./article-header/article-header";
import {
articlePropTypes,
articleDefaultProps
} from "./article-prop-types/article-prop-types";
import Meta from "./article-meta/article-meta";
import styles from "./styles";
class ArticleInDepth extends Component {
constructor(props) {
super(props);
this.renderHeader = this.renderHeader.bind(this);
}
renderHeader({ width }) {
const { article, onAuthorPress, onImagePress, onVideoPress } = this.props;
const {
backgroundColour,
bylines,
expirableFlags,
hasVideo,
headline,
label,
publicationName,
publishedTime,
shortHeadline,
standfirst,
textColour
} = article;
return (
<ResponsiveContext.Consumer>
{({ isTablet }) => (
<Fragment>
<ArticleHeader
backgroundColour={backgroundColour}
flags={expirableFlags}
hasVideo={hasVideo}
headline={getHeadline(headline, shortHeadline)}
isTablet={isTablet}
label={label}
standfirst={standfirst}
textColour={textColour}
/>
<ArticleLeadAsset
{...getLeadAsset(article)}
getImageCrop={getStandardTemplateCrop}
onImagePress={onImagePress}
onVideoPress={onVideoPress}
renderCaption={({ caption }) =>
caption && caption.text && <CentredCaption {...caption} />
}
style={[styles.leadAsset, isTablet && styles.leadAssetTablet]}
width={width}
/>
<View
style={[
styles.metaContainer,
isTablet && styles.metaContainerTablet
]}
>
<Meta
backgroundColour={backgroundColour}
bylines={bylines}
isTablet={isTablet}
onAuthorPress={onAuthorPress}
publicationName={publicationName}
publishedTime={publishedTime}
textColour={textColour}
/>
</View>
</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>
);
}
}
ArticleInDepth.propTypes = articlePropTypes;
ArticleInDepth.defaultProps = articleDefaultProps;
export default ArticleInDepth;