Created
September 10, 2015 18:39
-
-
Save KyleAMathews/d187432d984414580939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Relay from 'react-relay' | |
import _ from 'underscore' | |
import {Navigation} from 'react-router' | |
import SaveMixin from '../mixins/save' | |
import CreatePostMutation from '../mutations/CreatePost' | |
const PostCreate = React.createClass({ | |
displayName: 'NewPost', | |
mixins: [ | |
SaveMixin, | |
Navigation | |
], | |
getInitialState() { | |
return { | |
post: { | |
title: '', | |
body: '', | |
created_at: new Date().toJSON(), | |
} | |
} | |
}, | |
onChange(cb) { | |
let onSuccess = (response) => { | |
console.log(response) | |
} | |
let onFailure = (transaction) => { | |
let error = transaction.getError() | |
console.log(transaction); | |
console.log(error); | |
} | |
console.log(this.state.post, this.props) | |
Relay.Store.update(new CreatePostMutation({ | |
viewer: this.props.viewer, | |
title: this.state.post.title, | |
body: this.state.post.body, | |
created_at: this.state.post.created_at, | |
}), {onFailure, onSuccess}) | |
}, | |
componentDidMount() { | |
this.refs.title.focus() | |
} | |
}) | |
export default Relay.createContainer(PostCreate, { | |
fragments: { | |
viewer: () => Relay.QL` | |
fragment on User { | |
id | |
${CreatePostMutation.getFragment('viewer')} | |
} | |
` | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment