From a5f677a3773f879de9c48c49345bd8a7f8a1a3a7 Mon Sep 17 00:00:00 2001 From: Sam Coenen Date: Thu, 25 Jan 2018 15:31:22 +0100 Subject: [PATCH 1/4] Adding headers to the file inputs in preparation of Blob type support --- app/components/file-input.js | 1 + app/components/multiple-uploader.js | 2 +- app/components/single-uploader.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/components/file-input.js b/app/components/file-input.js index f9b3af5..95fc272 100644 --- a/app/components/file-input.js +++ b/app/components/file-input.js @@ -1,5 +1,6 @@ const FileInput = props => (
+

{props.title}

+ +) + +export default Field diff --git a/app/components/file-input.js b/app/components/file-input.js deleted file mode 100644 index 95fc272..0000000 --- a/app/components/file-input.js +++ /dev/null @@ -1,13 +0,0 @@ -const FileInput = props => ( -
-

{props.title}

- - -
-) - -export default FileInput diff --git a/app/components/section.js b/app/components/section.js new file mode 100644 index 0000000..fb85e50 --- /dev/null +++ b/app/components/section.js @@ -0,0 +1,15 @@ +const Section = ({ heading, children }) => ( +
+

{heading}

+ {children} + +
+) + +export default Section diff --git a/app/components/upload-blob.js b/app/components/upload-blob.js new file mode 100644 index 0000000..337cdb6 --- /dev/null +++ b/app/components/upload-blob.js @@ -0,0 +1,70 @@ +import { Component } from 'react' +import { graphql } from 'react-apollo' +import gql from 'graphql-tag' +import Field from './field' +import uploadsQuery from '../queries/uploads' + +class UploadBlob extends Component { + state = { + name: '', + content: '' + } + + handleChange = ({ target: { name, value } }) => + this.setState({ [name]: value }) + + handleSubmit = event => { + event.preventDefault() + + const file = new Blob([this.state.content], { type: 'text/plain' }) + file.name = `${this.state.name}.txt` + + this.props.mutate({ + variables: { file }, + update: (proxy, { data: { singleUpload } }) => { + const data = proxy.readQuery({ query: uploadsQuery }) + data.uploads.push(singleUpload) + proxy.writeQuery({ query: uploadsQuery, data }) + } + }) + } + + render() { + return ( +
+ + {' '} + .txt + + +