fixed spacing

This commit is contained in:
John Williamson 2017-11-26 13:11:13 +10:00
parent f2a8c12952
commit 5d1679d00a

View File

@ -1,6 +1,6 @@
import './style.css'
import React, { Component } from 'react' import React, { Component } from 'react'
import Gun from 'gun' import Gun from 'gun'
import './style.css'
const formatTodos = todos => Object.keys(todos) const formatTodos = todos => Object.keys(todos)
.map(key => ({ key, val: todos[key] })) .map(key => ({ key, val: todos[key] }))
@ -12,18 +12,23 @@ export default class Todos extends Component {
this.gun = gun.get('todos'); this.gun = gun.get('todos');
this.state = {newTodo: '', todos: []} this.state = {newTodo: '', todos: []}
} }
componentWillMount() { componentWillMount() {
this.gun.on(todos => this.setState({ this.gun.on(todos => this.setState({
todos: formatTodos(todos) todos: formatTodos(todos)
})) }))
} }
add = e => { add = e => {
e.preventDefault() e.preventDefault()
this.gun.path(Gun.text.random()).put(this.state.newTodo) this.gun.path(Gun.text.random()).put(this.state.newTodo)
this.setState({newTodo: ''}) this.setState({newTodo: ''})
} }
del = key => this.gun.path(key).put(null) del = key => this.gun.path(key).put(null)
handleChange = e => this.setState({ newTodo: e.target.value}) handleChange = e => this.setState({ newTodo: e.target.value})
render() { render() {
return <div> return <div>
<form onSubmit={this.add}> <form onSubmit={this.add}>
@ -36,5 +41,6 @@ export default class Todos extends Component {
</ul> </ul>
</div> </div>
} }
} }