1
+ <template >
2
+ <div class =' detail' >
3
+ <div class =" modal-mask" v-if =" showModal" @close =" showModal = false" >
4
+ <div class =" modal-wrapper" >
5
+ <div class =" modal-container" >
6
+
7
+ <div class =" modal-header" >
8
+ <slot name =" header" >
9
+ Add New Photo
10
+ </slot >
11
+ </div >
12
+
13
+ <div class =" modal-body" >
14
+ <slot name =" body" >
15
+ <input v-model =" description" placeholder =" Description" >
16
+ <input v-model =" imageUrl" placeholder =" Image url" >
17
+ <button @click =" create" >Create Post</button >
18
+ </slot >
19
+ </div >
20
+
21
+ <div class =" modal-footer" >
22
+ <slot name =" footer" >
23
+
24
+ <button @click =" showModal = false" >
25
+ Close Modal
26
+ </button >
27
+ </slot >
28
+ </div >
29
+ </div >
30
+ </div >
31
+ </div >
32
+ <div class =' createPost' @click =" showModal = true" >
33
+
34
+ <img src =" http://www.startuppassion.eu/wp-content/uploads/2017/03/plus-sign.png" class =" plusImage" alt =" " ><br >
35
+ <button class =' newPost' >NEW POST</button >
36
+ </div >
37
+ </div >
38
+ </template >
39
+
40
+ <script >
41
+ import gql from ' graphql-tag'
42
+ const CREATE_POST = gql `
43
+ mutation createPost ($description : String ! , $imageUrl : String ! ) {
44
+ createPost (description : $description , imageUrl : $imageUrl ) {
45
+ id
46
+ imageUrl
47
+ description
48
+ }
49
+ }
50
+ `
51
+ export default {
52
+ data : () => ({
53
+ description: ' ' ,
54
+ imageUrl: ' ' ,
55
+ showModal: false ,
56
+ }),
57
+
58
+ // Attribute
59
+ methods: {
60
+ create () {
61
+ const description = this .description
62
+ const imageUrl = this .imageUrl
63
+
64
+ this .description = ' '
65
+ this .imageUrl = ' '
66
+
67
+ // Mutation
68
+ this .$apollo .mutate ({
69
+ mutation: CREATE_POST ,
70
+ variables: {
71
+ description,
72
+ imageUrl,
73
+ },
74
+ updateQueries: {
75
+ allPosts: (prev, {
76
+ mutationResult
77
+ }) => {
78
+ return {
79
+ // append at head of list because we sort the posts reverse chronological
80
+ allPosts: [mutationResult .data .createPost , ... prev .allPosts ],
81
+ }
82
+ },
83
+ },
84
+ }).then ((data ) => {
85
+ // Result
86
+ console .log (data);
87
+ this .showModal = false ;
88
+ }).catch ((error ) => {
89
+ // Error
90
+ console .error (error)
91
+ })
92
+ },
93
+ },
94
+ }
95
+ </script >
96
+
97
+ <style >
98
+ .createPost {
99
+ /* Add shadows to create the "card" effect */
100
+ box-shadow : 0 4px 8px 0 rgba (0 , 0 , 0 , 0.2 );
101
+ transition : 0.3s ;
102
+ width : 300px ;
103
+ height : 300px ;
104
+ margin-top : 35px ;
105
+ float : left ;
106
+ }
107
+
108
+ .createPost :hover {
109
+ box-shadow : 0 8px 16px 0 rgba (0 , 0 , 0 , 0.2 );
110
+ }
111
+
112
+ .newPost {
113
+ border : none ;
114
+ color : gray ;
115
+ background-color : white ;
116
+ }
117
+
118
+ .plusImage {
119
+ opacity : 0.4 ;
120
+ margin-top : 25% ;
121
+ width : 25% ;
122
+ height : 25% ;
123
+ }
124
+
125
+ .modal-mask {
126
+ position : fixed ;
127
+ z-index : 9998 ;
128
+ top : 0 ;
129
+ left : 0 ;
130
+ width : 100% ;
131
+ height : 100% ;
132
+ background-color : rgba (0 , 0 , 0 , .5 );
133
+ display : table ;
134
+ transition : opacity .3s ease ;
135
+ }
136
+
137
+ .modal-wrapper {
138
+ display : table-cell ;
139
+ vertical-align : middle ;
140
+ }
141
+
142
+ .modal-container {
143
+ width : 400px ;
144
+ height : 200px ;
145
+ margin : 0px auto ;
146
+ padding : 20px 30px ;
147
+ background-color : #fff ;
148
+ border-radius : 2px ;
149
+ box-shadow : 0 2px 8px rgba (0 , 0 , 0 , .33 );
150
+ transition : all .3s ease ;
151
+ font-family : Helvetica , Arial , sans-serif ;
152
+ }
153
+
154
+ .modal-header h3 {
155
+ margin-top : 0 ;
156
+ color : #42b983 ;
157
+ }
158
+
159
+ .modal-body {
160
+ margin : 15% ;
161
+ }
162
+ .modal-enter {
163
+ opacity : 0 ;
164
+ }
165
+ .modal-footer {
166
+ float :right ;
167
+ }
168
+ .modal-leave-active {
169
+ opacity : 0 ;
170
+ }
171
+
172
+ .modal-enter .modal-container ,
173
+ .modal-leave-active .modal-container {
174
+ -webkit-transform : scale (1.1 );
175
+ transform : scale (1.1 );
176
+ }
177
+ /*
178
+ .create {
179
+ text-align: center;
180
+ display: flex;
181
+ justify-content: flex-start;
182
+ flex-direction: column;
183
+ }*/
184
+ </style >
0 commit comments