-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathcomment-list-item.component.js
225 lines (192 loc) · 5.34 KB
/
comment-list-item.component.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// @flow
/* eslint-disable no-nested-ternary */
import React, { Component } from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';
import { GithubHtmlView } from 'components';
import { Icon } from 'react-native-elements';
import ActionSheet from 'react-native-actionsheet';
import { t, relativeTimeToNow } from 'utils';
import { colors, fonts, normalize } from 'config';
const Container = styled.View`
padding: 10px 10px 0 0;
background-color: transparent;
`;
const Header = styled.View`
flex-direction: row;
margin-left: 10;
align-items: center;
`;
const AvatarContainer = styled.TouchableOpacity`
background-color: ${colors.greyLight};
border-radius: 17;
width: 34;
height: 34;
`;
const Avatar = styled.Image`
border-radius: 17;
width: 34;
height: 34;
`;
const TitleSubtitleContainer = styled.View`
justify-content: center;
flex: 1;
margin-left: 10;
`;
const DateContainer = styled.View`
flex: 0.15;
align-items: flex-end;
justify-content: center;
`;
const LinkDescription = styled.Text`
${{ ...fonts.fontPrimaryBold }};
font-size: ${normalize(13)};
color: ${colors.primaryDark};
`;
const DateLabel = styled.Text`
color: ${colors.greyDark};
`;
const CommentContainer = styled.View`
padding-top: 5;
margin-left: 54;
border-bottom-color: ${colors.greyLight};
border-bottom-width: 1;
padding-bottom: ${props => (props.bottomPadding ? 15 : 0)};
`;
const CommentTextNone = styled.Text`
${{ ...fonts.fontPrimary }};
color: ${colors.primaryDark};
font-style: italic;
`;
const ActionButtonIconContainer = styled.View`
padding: 5px 0 10px;
align-items: flex-end;
justify-content: center;
`;
const mapStateToProps = state => ({
authUser: state.auth.user,
});
class CommentListItemComponent extends Component {
props: {
comment: Object,
onLinkPress: Function,
onEditPress: Function,
onDeletePress: Function,
locale: string,
navigation: Object,
authUser: Object,
};
ActionSheet: ActionSheet;
handlePress = (index: number) => {
const { onDeletePress, onEditPress, comment } = this.props;
if (index === 0) {
onEditPress(comment);
} else if (index === 1) {
onDeletePress(comment);
}
};
showMenu = () => {
this.ActionSheet.show();
};
isIssueDescription = () =>
Object.prototype.hasOwnProperty.call(this.props.comment, 'repository_url');
commentActionSheetOptions = comment => {
const { locale } = this.props;
const actions = [t('Edit', locale)];
if (!comment.repository_url) {
actions.push(t('Delete', locale));
}
return actions;
};
render() {
const { comment, locale, navigation, authUser, onLinkPress } = this.props;
const commentPresent = comment.body_html && comment.body_html !== '';
const isActionMenuEnabled =
comment.user && authUser.login === comment.user.login;
return (
<Container>
<Header>
{comment.user && (
<AvatarContainer
onPress={() =>
navigation.navigate(
authUser.login === comment.user.login
? 'AuthProfile'
: 'Profile',
{
user: comment.user,
}
)
}
>
<Avatar
source={{
uri: comment.user.avatar_url,
}}
/>
</AvatarContainer>
)}
{comment.user && (
<TitleSubtitleContainer>
<LinkDescription
onPress={() =>
navigation.navigate(
authUser.login === comment.user.login
? 'AuthProfile'
: 'Profile',
{
user: comment.user,
}
)
}
>
{comment.user.login}
</LinkDescription>
</TitleSubtitleContainer>
)}
<DateContainer>
<DateLabel>{relativeTimeToNow(comment.created_at)}</DateLabel>
</DateContainer>
</Header>
<CommentContainer bottomPadding={!isActionMenuEnabled}>
{commentPresent ? (
<GithubHtmlView
source={comment.body_html}
onLinkPress={onLinkPress}
/>
) : (
<CommentTextNone>
{t('No description provided.', locale)}
</CommentTextNone>
)}
{isActionMenuEnabled && (
<ActionButtonIconContainer>
<Icon
color={colors.grey}
size={20}
name="ellipsis-h"
type="font-awesome"
onPress={this.showMenu}
/>
</ActionButtonIconContainer>
)}
</CommentContainer>
<ActionSheet
ref={o => {
this.ActionSheet = o;
}}
title={t('Comment Actions', locale)}
options={[
...this.commentActionSheetOptions(comment),
t('Cancel', locale),
]}
cancelButtonIndex={this.commentActionSheetOptions(comment).length}
onPress={this.handlePress}
/>
</Container>
);
}
}
export const CommentListItem = connect(mapStateToProps)(
CommentListItemComponent
);