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/CreateItem.js | 148 --------------------- 1 file changed, 148 deletions(-) delete mode 100644 finished-application/frontend/components/CreateItem.js (limited to 'finished-application/frontend/components/CreateItem.js') diff --git a/finished-application/frontend/components/CreateItem.js b/finished-application/frontend/components/CreateItem.js deleted file mode 100644 index 503b3cb..0000000 --- a/finished-application/frontend/components/CreateItem.js +++ /dev/null @@ -1,148 +0,0 @@ -import React, { Component } from 'react'; -import { Mutation } from 'react-apollo'; -import Router from 'next/router'; -import wait from 'waait'; -import gql from 'graphql-tag'; -import Error from './ErrorMessage'; -import Form from './styles/Form'; -import formatMoney from '../lib/formatMoney'; -import { ALL_ITEMS_QUERY } from './Items'; -import { PAGINATION_QUERY } from './Pagination'; - -const CREATE_ITEM_MUTATION = gql` - mutation CREATE_ITEM_MUTATION( - $description: String! - $title: String! - $price: Int! - $image: String - $largeImage: String - ) { - createItem( - description: $description - title: $title - price: $price - image: $image - largeImage: $largeImage - ) { - id - } - } -`; - -class CreateItem extends Component { - state = { - title: '', - description: '', - image: '', - largeImage: '', - price: 0, - }; - - handleChange = e => { - const { name, value, type } = e.target; - const val = type === 'number' ? parseFloat(value) : value; - this.setState({ [name]: val }); - }; - - uploadFile = async e => { - this.setState({ loading: true }); - const files = e.currentTarget.files; - const data = new FormData(); - data.append('file', files[0]); - data.append('upload_preset', 'sickfits'); - - // use the file endpoint - const res = await fetch('https://api.cloudinary.com/v1_1/wesbos/image/upload', { - method: 'POST', - body: data, - }); - const file = await res.json(); - this.setState({ - image: file.secure_url, - largeImage: file.eager[0].secure_url, - loading: false, - }); - }; - - render() { - return ( - - {(createItem, { loading, error }) => ( -
{ - e.preventDefault(); - const { data: { createItem: item } } = await createItem(); - // we wait 0 ms so it puts the router push at the end of the call stack. This ensures that refetchQueries runs before we unmount the component :) - await wait(); - Router.push({ - pathname: `/item`, - query: { id: item.id }, - }); - }} - > -

Sell an Item.

- -
- - - -