-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentMutation.js
135 lines (131 loc) · 3.27 KB
/
CommentMutation.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
import React from 'react';
import gql from 'graphql-tag';
import { Mutation, graphql, compose } from 'react-apollo';
import { Modal, View, TextInput } from 'react-native';
import { Button } from 'react-native-elements';
//to set up the query for comment mutation
const ADD_COMMENT = gql`
mutation addComment($input: CommentCreateInput) {
addComment(input: $input) {
text
userId
}
}
`;
//to set up the query for user data
const Query = gql`
{
users {
_id
firstname
lastname
email
}
}
`;
const AddComment = props => (
<Mutation
mutation={ADD_COMMENT}
refetchQueries={() => {
const queryPosts = gql`
query getPosts($filters: JSON, $options: JSON) {
posts(filters: $filters, options: $options) {
_id
categoryId
userId
title
description
createdAt
user {
_id
firstname
lastname
email
}
category {
_id
name
}
tags {
_id
name
}
comments {
user {
firstname
lastname
email
}
text
createdAt
}
}
}
`;
return [
{
query: queryPosts,
variables: {
filters: props.filter
}
}
];
}}
>
{(addComment) => (
<View>
<Modal
animationType="slide"
transparent
visible={props.visible}
>
<View
style={{
flex: 1,
paddingTop: 220,
backgroundColor: 'rgba(52, 52, 52, 0.8)'
}}
>
<TextInput
style={{
height: 150,
borderColor: 'white',
borderWidth: 1,
backgroundColor: 'white',
margin: 15,
padding: 10
}}
placeholder="Your Comment"
onChangeText={text => props.updateText(text)}
/>
<Button
onPress={() => {
addComment({
variables: {
input: {
text: props.singleComment,
postId: props.postId,
userId:
props.data.users[Math.floor(Math.random() * 10)]._id
}
}
});
props.visible();
}}
MaterialCommunityIcons={{ name: 'comment-outline' }}
backgroundColor='#03A9F4'
buttonStyle={{
borderRadius: 0,
marginLeft: 0,
marginRight: 0,
marginBottom: 0
}}
title="Send"
/>
</View>
</Modal>
</View>
)}
</Mutation>
);
export default compose(graphql(Query))(AddComment);