Skip to content

Commit 1947f1c

Browse files
chinesedfanmachour
authored andcommitted
refactor: use styled-components in comment-list-item (#723)
1 parent e346139 commit 1947f1c

File tree

2 files changed

+93
-101
lines changed

2 files changed

+93
-101
lines changed

.stylelintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"block-no-empty": null,
99
"declaration-colon-newline-after": null,
1010
"declaration-property-value-whitelist": {
11-
"margin": ["/^(0|[+-]?(\\d*\\.)?\\d+px)( (0|[+-]?(\\d*\\.)?\\d+px))?$/"],
12-
"padding": ["/^(0|[+-]?(\\d*\\.)?\\d+px)( (0|[+-]?(\\d*\\.)?\\d+px))?$/"],
11+
"margin": ["/^(0|[+-]?(\\d*\\.)?\\d+px)( (0|[+-]?(\\d*\\.)?\\d+px)){0,3}$/"],
12+
"padding": ["/^(0|[+-]?(\\d*\\.)?\\d+px)( (0|[+-]?(\\d*\\.)?\\d+px)){0,3}$/"],
1313
},
1414
"value-list-max-empty-lines": null
1515
},

src/components/comment-list-item.component.js

+91-99
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,79 @@
33

44
import React, { Component } from 'react';
55
import { connect } from 'react-redux';
6-
import { StyleSheet, View, Text, TouchableOpacity, Image } from 'react-native';
6+
import styled from 'styled-components';
77
import { GithubHtmlView } from 'components';
88
import { Icon } from 'react-native-elements';
99
import ActionSheet from 'react-native-actionsheet';
1010

1111
import { translate, relativeTimeToNow } from 'utils';
1212
import { colors, fonts, normalize } from 'config';
1313

14-
const styles = StyleSheet.create({
15-
container: {
16-
paddingRight: 10,
17-
paddingTop: 10,
18-
backgroundColor: 'transparent',
19-
},
20-
header: {
21-
flexDirection: 'row',
22-
marginLeft: 10,
23-
alignItems: 'center',
24-
},
25-
avatarContainer: {
26-
backgroundColor: colors.greyLight,
27-
borderRadius: 17,
28-
width: 34,
29-
height: 34,
30-
},
31-
avatar: {
32-
width: 34,
33-
height: 34,
34-
borderRadius: 17,
35-
},
36-
titleSubtitleContainer: {
37-
justifyContent: 'center',
38-
flex: 1,
39-
marginLeft: 10,
40-
},
41-
dateContainer: {
42-
flex: 0.15,
43-
alignItems: 'flex-end',
44-
justifyContent: 'center',
45-
},
46-
linkDescription: {
47-
...fonts.fontPrimaryBold,
48-
fontSize: normalize(13),
49-
color: colors.primaryDark,
50-
},
51-
date: {
52-
color: colors.greyDark,
53-
},
54-
commentContainer: {
55-
paddingTop: 5,
56-
marginLeft: 54,
57-
borderBottomColor: colors.greyLight,
58-
borderBottomWidth: 1,
59-
},
60-
commentBottomPadding: {
61-
paddingBottom: 15,
62-
},
63-
commentText: {
64-
fontSize: normalize(12),
65-
color: colors.primaryDark,
66-
},
67-
commentTextNone: {
68-
...fonts.fontPrimary,
69-
color: colors.primaryDark,
70-
fontStyle: 'italic',
71-
},
72-
actionButtonIconContainer: {
73-
paddingTop: 5,
74-
paddingBottom: 10,
75-
alignItems: 'flex-end',
76-
justifyContent: 'center',
77-
},
78-
});
14+
const Container = styled.View`
15+
padding: 10px 10px 0 0;
16+
background-color: transparent;
17+
`;
18+
19+
const Header = styled.View`
20+
flex-direction: row;
21+
margin-left: 10;
22+
align-items: center;
23+
`;
24+
25+
const AvatarContainer = styled.TouchableOpacity`
26+
background-color: ${colors.greyLight};
27+
border-radius: 17;
28+
width: 34;
29+
height: 34;
30+
`;
31+
32+
const Avatar = styled.Image`
33+
border-radius: 17;
34+
width: 34;
35+
height: 34;
36+
`;
37+
38+
const TitleSubtitleContainer = styled.View`
39+
justify-content: center;
40+
flex: 1;
41+
margin-left: 10;
42+
`;
43+
44+
const DateContainer = styled.View`
45+
flex: 0.15;
46+
align-items: flex-end;
47+
justify-content: center;
48+
`;
49+
50+
const LinkDescription = styled.Text`
51+
${{ ...fonts.fontPrimaryBold }};
52+
font-size: ${normalize(13)};
53+
color: ${colors.primaryDark};
54+
`;
55+
56+
const DateLabel = styled.Text`
57+
color: ${colors.greyDark};
58+
`;
59+
60+
const CommentContainer = styled.View`
61+
padding-top: 5;
62+
margin-left: 54;
63+
border-bottom-color: ${colors.greyLight};
64+
border-bottom-width: 1;
65+
padding-bottom: ${props => (props.bottomPadding ? 15 : 0)};
66+
`;
67+
68+
const CommentTextNone = styled.Text`
69+
${{ ...fonts.fontPrimary }};
70+
color: ${colors.primaryDark};
71+
font-style: italic;
72+
`;
73+
74+
const ActionButtonIconContainer = styled.View`
75+
padding: 5px 0 10px;
76+
align-items: flex-end;
77+
justify-content: center;
78+
`;
7979

8080
const mapStateToProps = state => ({
8181
authUser: state.auth.user,
@@ -131,11 +131,10 @@ class CommentListItemComponent extends Component {
131131
comment.user && authUser.login === comment.user.login;
132132

133133
return (
134-
<View style={styles.container}>
135-
<View style={styles.header}>
134+
<Container>
135+
<Header>
136136
{comment.user && (
137-
<TouchableOpacity
138-
style={styles.avatarContainer}
137+
<AvatarContainer
139138
onPress={() =>
140139
navigation.navigate(
141140
authUser.login === comment.user.login
@@ -144,21 +143,20 @@ class CommentListItemComponent extends Component {
144143
{
145144
user: comment.user,
146145
}
147-
)}
146+
)
147+
}
148148
>
149-
<Image
150-
style={styles.avatar}
149+
<Avatar
151150
source={{
152151
uri: comment.user.avatar_url,
153152
}}
154153
/>
155-
</TouchableOpacity>
154+
</AvatarContainer>
156155
)}
157156

158157
{comment.user && (
159-
<View style={styles.titleSubtitleContainer}>
160-
<Text
161-
style={styles.linkDescription}
158+
<TitleSubtitleContainer>
159+
<LinkDescription
162160
onPress={() =>
163161
navigation.navigate(
164162
authUser.login === comment.user.login
@@ -167,49 +165,43 @@ class CommentListItemComponent extends Component {
167165
{
168166
user: comment.user,
169167
}
170-
)}
168+
)
169+
}
171170
>
172171
{comment.user.login}
173-
</Text>
174-
</View>
172+
</LinkDescription>
173+
</TitleSubtitleContainer>
175174
)}
176175

177-
<View style={styles.dateContainer}>
178-
<Text style={styles.date}>
179-
{relativeTimeToNow(comment.created_at)}
180-
</Text>
181-
</View>
182-
</View>
183-
184-
<View
185-
style={[
186-
styles.commentContainer,
187-
!isActionMenuEnabled && styles.commentBottomPadding,
188-
]}
189-
>
176+
<DateContainer>
177+
<DateLabel>{relativeTimeToNow(comment.created_at)}</DateLabel>
178+
</DateContainer>
179+
</Header>
180+
181+
<CommentContainer bottomPadding={!isActionMenuEnabled}>
190182
{commentPresent ? (
191183
<GithubHtmlView
192184
source={comment.body_html}
193185
onLinkPress={onLinkPress}
194186
/>
195187
) : (
196-
<Text style={styles.commentTextNone}>
188+
<CommentTextNone>
197189
{translate('issue.main.noDescription', locale)}
198-
</Text>
190+
</CommentTextNone>
199191
)}
200192

201193
{isActionMenuEnabled && (
202-
<View style={styles.actionButtonIconContainer}>
194+
<ActionButtonIconContainer>
203195
<Icon
204196
color={colors.grey}
205197
size={20}
206198
name={'ellipsis-h'}
207199
type={'font-awesome'}
208200
onPress={this.showMenu}
209201
/>
210-
</View>
202+
</ActionButtonIconContainer>
211203
)}
212-
</View>
204+
</CommentContainer>
213205

214206
<ActionSheet
215207
ref={o => {
@@ -223,7 +215,7 @@ class CommentListItemComponent extends Component {
223215
cancelButtonIndex={this.commentActionSheetOptions(comment).length}
224216
onPress={this.handlePress}
225217
/>
226-
</View>
218+
</Container>
227219
);
228220
}
229221
}

0 commit comments

Comments
 (0)