@@ -72,7 +72,7 @@ class Review extends Component {
72
72
73
73
delete = ( ) => {
74
74
this . closeDeleteConfirmation ( )
75
- this . props . delete ( this . props . review . id ) . catch ( e => {
75
+ this . props . delete ( this . props . review . id , this . props . orderBy ) . catch ( e => {
76
76
if ( find ( e . graphQLErrors , { message : 'unauthorized' } ) ) {
77
77
alert ( '👮♀️✋ You can only delete your own reviews!' )
78
78
}
@@ -181,7 +181,8 @@ class Review extends Component {
181
181
Review . propTypes = {
182
182
review : propType ( REVIEW_ENTRY ) . isRequired ,
183
183
favorite : PropTypes . func . isRequired ,
184
- user : PropTypes . object
184
+ user : PropTypes . object ,
185
+ orderBy : PropTypes . string . isRequired
185
186
}
186
187
187
188
const FAVORITE_REVIEW_MUTATION = gql `
@@ -239,7 +240,7 @@ const DELETE_REVIEW_MUTATION = gql`
239
240
240
241
const withDeleteMutation = graphql ( DELETE_REVIEW_MUTATION , {
241
242
props : ( { mutate } ) => ( {
242
- delete : id =>
243
+ delete : ( id , orderBy ) =>
243
244
mutate ( {
244
245
variables : { id } ,
245
246
optimisticResponse : {
@@ -248,21 +249,13 @@ const withDeleteMutation = graphql(DELETE_REVIEW_MUTATION, {
248
249
update : store => {
249
250
const query = {
250
251
query : REVIEWS_QUERY ,
251
- variables : { limit : 10 , orderBy : 'createdAt_DESC' }
252
+ variables : { limit : 10 , orderBy }
252
253
}
253
254
254
255
let data = store . readQuery ( query )
255
256
remove ( data . reviews , { id } )
256
257
store . writeQuery ( { ...query , data } )
257
258
258
- query . variables . orderBy = 'createdAt_ASC'
259
-
260
- try {
261
- data = store . readQuery ( query )
262
- remove ( data . reviews , { id } )
263
- store . writeQuery ( { ...query , data } )
264
- } catch ( e ) { }
265
-
266
259
data = store . readQuery ( { query : READ_USER_FAVORITES } )
267
260
remove ( data . currentUser . favoriteReviews , { id } )
268
261
store . writeQuery ( { query : READ_USER_FAVORITES , data } )
@@ -271,4 +264,7 @@ const withDeleteMutation = graphql(DELETE_REVIEW_MUTATION, {
271
264
} )
272
265
} )
273
266
274
- export default compose ( withFavoriteMutation , withDeleteMutation ) ( Review )
267
+ export default compose (
268
+ withFavoriteMutation ,
269
+ withDeleteMutation
270
+ ) ( Review )
0 commit comments