Last active
January 7, 2019 13:51
-
-
Save strongSoda/fcbed97a4ea770cf591419965a260e17 to your computer and use it in GitHub Desktop.
This file contains 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, { Component } from 'react'; | |
import { addTodo } from './QueryAddTodos'; | |
import { getTodos } from './QuerygetTodos'; | |
import { FontAwesomeIcon} from '@fortawesome/react-fontawesome'; | |
import Form from 'react-bootstrap/lib/Form'; | |
import FormControl from 'react-bootstrap/lib/FormControl'; | |
import FormGroup from 'react-bootstrap/lib/FormGroup'; | |
import InputGroup from 'react-bootstrap/lib/InputGroup'; | |
import Button from 'react-bootstrap/lib/Button'; | |
import { faPlus } from '@fortawesome/free-solid-svg-icons'; | |
import { Mutation } from "react-apollo"; | |
class AddTodo extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
todo_text: "", | |
todo_user: "" | |
} | |
} | |
addtodo(insert_todos) { | |
var todo_user = localStorage.getItem('sub'); | |
this.setState({ todo_user: todo_user }, function () { | |
insert_todos({ variables: this.state, refetchQueries: [{ query: getTodos }] }); | |
}); | |
} | |
render() { | |
return ( | |
<Mutation mutation={addTodo}> | |
{(insert_todos, { data }) => ( | |
<Form | |
onSubmit={e => { | |
e.preventDefault(); | |
this.addtodo(insert_todos); | |
}} | |
> | |
{ | |
<FormGroup controlId="Createtodo" > | |
<InputGroup> | |
<FormControl | |
type="text" | |
value={this.state.todo_text} | |
placeholder="Create a todo task." | |
onChange={e => this.setState({ todo_text: e.target.value })} | |
/> | |
<InputGroup.Button> | |
<Button type="submit"><FontAwesomeIcon icon={faPlus} style={{ color: 'blue' }} /></Button> | |
</InputGroup.Button> | |
</InputGroup> | |
</FormGroup> | |
} | |
</Form> | |
)} | |
</Mutation> | |
); | |
} | |
} | |
export default AddTodo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment