Skip to content

Commit 0592f57

Browse files
committed
added conditions for deleting a comment
1 parent 525f98e commit 0592f57

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

src/gists/screens/components/SingleGistOverview.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ const DetailsText = styled.Text`
2929
color: ${colors.greyDark}
3030
`;
3131

32-
const TitleContainer = styled.View`
33-
display: flex;
34-
flex-direction: row;
35-
justify-content: space-between;
36-
`;
37-
38-
const IconContainer = styled.TouchableOpacity`
39-
margin: 3px 0;
40-
`;
41-
4232
class GistOverview extends React.Component {
4333
// shouldComponentUpdate(nextProps) {
4434
// return !(isEqual(this.props.gistData, nextProps.gistData));
@@ -54,12 +44,7 @@ class GistOverview extends React.Component {
5444

5545
return (
5646
<Container onPress={() => onClickGist(gistData)}>
57-
<TitleContainer>
58-
<Title>{title}</Title>
59-
<IconContainer>
60-
<Icon name="star-outline" size={18} />
61-
</IconContainer>
62-
</TitleContainer>
47+
<Title>{title}</Title>
6348
<DetailsContainer>
6449
<DetailsText>{moment(gistData.created_at).format('DD MMM YYYY')}</DetailsText>
6550
<DetailsText right>{pluralize('File', Object.keys(gistData.files).length, true)}</DetailsText>

src/gists/screens/gistComments.screen.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class GistCommentsScreen extends React.Component {
8484
this.state = {
8585
comment: '',
8686
isVisible: false,
87-
id: null,
87+
commentId: null,
8888
};
8989
}
9090
componentDidMount() {
@@ -103,10 +103,11 @@ class GistCommentsScreen extends React.Component {
103103
this.setState({ isVisible: false });
104104
}
105105

106-
openGistOptions = id => {
106+
openGistOptions = (commentId, userId) => {
107+
if (userId !== this.props.currentUserId) return;
107108
this.setState({
108109
isVisible: true,
109-
id,
110+
commentId,
110111
});
111112
}
112113

@@ -118,13 +119,15 @@ class GistCommentsScreen extends React.Component {
118119
this.onCancel();
119120
this.props.deleteThisComment({
120121
gistId: this.props.navigation.getParam('gistData').id,
121-
commentId: this.state.id,
122+
commentId: this.state.commentId,
122123
});
123124
}
124125

125126
renderItem = ({ item }) => {
126127
return (
127-
<TouchableOpacity style={{ flex: 1 }} onLongPress={() => this.openGistOptions(item.id)}>
128+
<TouchableOpacity
129+
style={{ flex: 1 }}
130+
onLongPress={() => this.openGistOptions(item.id, item.user.id)}>
128131
<CardContainer
129132
cardElevation={2}
130133
cardMaxElevation={2}
@@ -194,9 +197,9 @@ const mapDispatchToProps = dispatch => ({
194197
deleteThisComment: data => dispatch(deleteComment.action(data)),
195198
addThisComment: data => dispatch(addComment.action(data)),
196199
});
197-
const mapStateToProps = ({ gistComments, auth }) => ({
200+
const mapStateToProps = ({ gistComments, loggedInUser }) => ({
198201
comments: gistComments.comments,
199-
accessToken: auth.access_token,
202+
currentUserId: loggedInUser.userId,
200203
inProgress: gistComments.inProgress,
201204
});
202205

0 commit comments

Comments
 (0)