-
Notifications
You must be signed in to change notification settings - Fork 42
/
author-head.js
132 lines (120 loc) · 2.98 KB
/
author-head.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
import React, { Component } from "react";
import { View, StyleSheet, Platform } from "react-native";
import PropTypes from "prop-types";
import { TextLink } from "@times-components/link";
import { treePropType } from "@times-components/markup";
import { IconTwitter } from "@times-components/icons";
import {
colours,
fonts,
fontSizes,
spacing
} from "@times-components/styleguide";
import { withTrackEvents } from "@times-components/tracking";
import AuthorTitle from "./author-title";
import Bio from "./author-bio";
import AuthorName from "./author-name";
import AuthorPhoto from "./author-photo";
import AuthorHeadContainer from "./author-head-container";
import AuthorHeadLoading from "./author-head-loading";
const styles = StyleSheet.create({
twitter: {
paddingTop: 8,
paddingBottom: 8,
flexDirection: "row",
...Platform.select({
android: {
alignItems: "center"
}
})
},
twitterLink: {
fontSize: fontSizes.tertiary,
fontFamily: fonts.supporting,
color: colours.functional.action,
textDecorationLine: "none",
paddingLeft: spacing(1)
}
});
class AuthorHead extends Component {
shouldComponentUpdate(nextProps) {
return this.props.isLoading !== nextProps.isLoading;
}
render() {
const {
bio,
isLoading,
name,
onTwitterLinkPress,
title,
twitter,
uri
} = this.props;
if (isLoading) return <AuthorHeadLoading />;
return (
<AuthorHeadContainer>
<AuthorPhoto uri={uri} />
<AuthorName name={name} />
<AuthorTitle title={title} />
<TwitterLink handle={twitter} onPress={onTwitterLinkPress} />
<Bio bio={bio} />
</AuthorHeadContainer>
);
}
}
AuthorHead.defaultProps = {
isLoading: false,
name: "",
title: "",
uri: "",
bio: [],
twitter: null,
onTwitterLinkPress: () => {}
};
AuthorHead.propTypes = {
isLoading: PropTypes.bool,
name: PropTypes.string,
title: PropTypes.string,
uri: PropTypes.string,
bio: PropTypes.arrayOf(treePropType),
twitter: PropTypes.string,
onTwitterLinkPress: PropTypes.func
};
const TwitterLink = ({ handle, onPress }) => {
if (!handle) {
return null;
}
const url = `https://twitter.com/${handle}`;
return (
<View style={styles.twitter}>
<IconTwitter width={15} height={15} />
<TextLink
style={styles.twitterLink}
url={url}
onPress={e => onPress(e, { handle, url })}
>
@{handle}
</TextLink>
</View>
);
};
TwitterLink.propTypes = {
handle: AuthorHead.propTypes.twitter,
onPress: PropTypes.func.isRequired
};
TwitterLink.defaultProps = {
handle: AuthorHead.defaultProps.twitter
};
export default withTrackEvents(AuthorHead, {
analyticsEvents: [
{
eventName: "onTwitterLinkPress",
actionName: "Pressed",
trackingName: "TwitterLink",
getAttrs: (props, eventArgs) => ({
twitterHandle: props.twitter,
url: eventArgs[1] && eventArgs[1].url
})
}
]
});