diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-09-14 12:18:12 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-09-14 12:18:12 -0400 |
| commit | 2d145b026cfdf54a63bef0b9d6324b6785390307 (patch) | |
| tree | f6c1d8f987437803a5c026e70535bf9ff244e885 /stepped-solutions/FINISHED/frontend/components/DeleteItem.js | |
| parent | 8a5825d52271d712ec7c8348447d433067e13ef2 (diff) | |
move finished folder
Diffstat (limited to 'stepped-solutions/FINISHED/frontend/components/DeleteItem.js')
| -rw-r--r-- | stepped-solutions/FINISHED/frontend/components/DeleteItem.js | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/stepped-solutions/FINISHED/frontend/components/DeleteItem.js b/stepped-solutions/FINISHED/frontend/components/DeleteItem.js deleted file mode 100644 index e5e4752..0000000 --- a/stepped-solutions/FINISHED/frontend/components/DeleteItem.js +++ /dev/null @@ -1,50 +0,0 @@ -import React, { Component } from 'react'; -import { Mutation } from 'react-apollo'; -import gql from 'graphql-tag'; -import { ALL_ITEMS_QUERY } from './Items'; - -const DELETE_ITEM_MUTATION = gql` - mutation DELETE_ITEM_MUTATION($id: ID!) { - deleteItem(id: $id) { - id - } - } -`; - -class DeleteItem extends Component { - update = (cache, payload) => { - // manually update the cache on the client, so it matches the server - // 1. Read the cache for the items we want - const data = cache.readQuery({ query: ALL_ITEMS_QUERY }); - console.log(data, payload); - // 2. Filter the deleted itemout of the page - data.items = data.items.filter(item => item.id !== payload.data.deleteItem.id); - // 3. Put the items back! - cache.writeQuery({ query: ALL_ITEMS_QUERY, data }); - }; - render() { - return ( - <Mutation - mutation={DELETE_ITEM_MUTATION} - variables={{ id: this.props.id }} - update={this.update} - > - {(deleteItem, { error }) => ( - <button - onClick={() => { - if (confirm('Are you sure you want to delete this item?')) { - deleteItem().catch(err => { - alert(err.message); - }); - } - }} - > - {this.props.children} - </button> - )} - </Mutation> - ); - } -} - -export default DeleteItem; |
