From 8a5825d52271d712ec7c8348447d433067e13ef2 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 13 Sep 2018 14:18:56 -0400 Subject: DONE --- .../frontend/components/DeleteItem.js | 71 ---------------------- 1 file changed, 71 deletions(-) delete mode 100644 finished-application/frontend/components/DeleteItem.js (limited to 'finished-application/frontend/components/DeleteItem.js') diff --git a/finished-application/frontend/components/DeleteItem.js b/finished-application/frontend/components/DeleteItem.js deleted file mode 100644 index 4d68d5e..0000000 --- a/finished-application/frontend/components/DeleteItem.js +++ /dev/null @@ -1,71 +0,0 @@ -import React from 'react'; -import { Mutation } from 'react-apollo'; -import PropTypes, { number } from 'prop-types'; -import gql from 'graphql-tag'; -import { withRouter } from 'next/router'; -import { ALL_ITEMS_QUERY } from './Items'; -import { PAGINATION_QUERY } from './Pagination'; -import { perPage } from '../config'; - -const DELETE_ITEM_MUTATION = gql` - mutation deleteItem($id: ID!) { - deleteItem(id: $id) { - id - title - description - } - } -`; - -class DeleteItem extends React.Component { - static propTypes = { - id: PropTypes.string.isRequired, - }; - - update = (cache, payload) => { - const deletedItem = payload.data.deleteItem; - let { page = 1 } = this.props.router.query; - page = parseFloat(page); - const skip = page * perPage - perPage; - const variables = { skip }; - const data = cache.readQuery({ query: ALL_ITEMS_QUERY, variables }); - // filter this one out - data.items = data.items.filter(item => item.id !== deletedItem.id); - // write the data back to the cache - console.log(data.items); - cache.writeQuery({ query: ALL_ITEMS_QUERY, data, variables }); - // FYI Pagination is broken with Apollo currently - will make a followup video - }; - - render() { - return ( - - {(removeItem, { error }) => ( - - )} - - ); - } -} - -export default withRouter(DeleteItem); -export { DELETE_ITEM_MUTATION }; -- cgit v1.3