New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/create-update-todo-process #29
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ff21960
add updateTodo process
ha-matsumu ab97c0a
add TodoForm style
ha-matsumu 3dcca79
add selectTodo process and updateTodo process
ha-matsumu cee41c0
add click event
ha-matsumu 9063c39
remove conosle.log
ha-matsumu 13a780d
add binding
ha-matsumu 9d668ed
rename function
ha-matsumu 9d979ba
add prop-types
ha-matsumu 7a3731a
modify Mistake of code
ha-matsumu a981916
rename selectedTodo -> selectTodo
ha-matsumu 31ee59b
move AddTodoForm code from TodoForm
ha-matsumu 518e0df
move UpdateTodoForm code from TodoForm
ha-matsumu 916574a
split TodoForm code
ha-matsumu 883e9dd
modify TodoForm
ha-matsumu 99a79e9
remove comment
ha-matsumu 32e580c
add async/await
ha-matsumu 7531f64
add async/await
ha-matsumu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import axios from "axios"; | ||
|
||
import "./TodoForm.css"; | ||
|
||
class UpdateTodoForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
id: null, | ||
title: "", | ||
body: "", | ||
completed: false | ||
}; | ||
|
||
this.handleInputChange = this.handleInputChange.bind(this); | ||
this.updateTodoHandler = this.updateTodoHandler.bind(this); | ||
} | ||
|
||
// static getDerivedStateFromProps(nextProps, prevState) { | ||
// console.log("props :", nextProps); | ||
// console.log("state : ", prevState); | ||
// if (nextProps.selectedTodoId !== prevState.id) { | ||
// return { | ||
// id: null | ||
// }; | ||
// } | ||
// return null; | ||
// } | ||
|
||
componentDidUpdate() { | ||
if (this.props.selectedTodoId !== this.state.id) { | ||
axios.get("/api/todos/" + this.props.selectedTodoId).then(response => { | ||
this.setState({ | ||
id: response.data.id, | ||
title: response.data.title, | ||
body: response.data.body, | ||
completed: response.data.completed | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
handleInputChange = event => { | ||
const target = event.target; | ||
const value = target.value; | ||
const name = target.name; | ||
|
||
this.setState({ | ||
[name]: value | ||
}); | ||
}; | ||
|
||
updateTodoHandler = () => { | ||
if (!this.state.title) return; | ||
const todo = { | ||
id: this.state.id, | ||
title: this.state.title, | ||
body: this.state.body, | ||
completed: this.state.completed | ||
}; | ||
this.props.updateTodo(todo); | ||
this.props.resetStateHandler(); | ||
this.setState({ | ||
id: null, | ||
title: "", | ||
body: "", | ||
completed: false, | ||
requestAdd: true | ||
}); | ||
}; | ||
|
||
render() { | ||
console.log(this.state.id); | ||
console.log(this.state.title); | ||
console.log(this.state.body); | ||
console.log(this.state.completed); | ||
return ( | ||
<div className="todoForm"> | ||
<h1>Update Todo</h1> | ||
<label> | ||
Title | ||
<input | ||
name="title" | ||
type="text" | ||
value={this.state.title} | ||
onChange={this.handleInputChange} | ||
/> | ||
</label> | ||
<label> | ||
Body | ||
<textarea | ||
name="body" | ||
rows="4" | ||
value={this.state.body} | ||
onChange={this.handleInputChange} | ||
/> | ||
</label> | ||
<label> | ||
completed | ||
<select | ||
name="completed" | ||
value={this.state.completed} | ||
onChange={this.handleInputChange} | ||
> | ||
<option value="false">false</option> | ||
<option value="true">true</option> | ||
</select> | ||
</label> | ||
<button onClick={this.updateTodoHandler}>Update Todo</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
UpdateTodoForm.propTypes = { | ||
updateTodo: PropTypes.func.isRequired, | ||
selectedTodoId: PropTypes.number, | ||
resetStateHandler: PropTypes.func.isRequired | ||
}; | ||
|
||
export default UpdateTodoForm; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#29 (comment)
↑
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ha-matsumu/todo-with-express-and-mysql/pull/29/files#diff-c1caf12af6ad83889346e8124b766646R36
↑
AddTodoFormの
this.props.addTodo(todo);
も同様