Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "itss_std_react",
"name": "thienanblog",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Todo App</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
50 changes: 40 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@ import React, { Component } from 'react';
import ToDoListItem from "./ToDoListItem.js"
import './App.css';

import TodoForm from './TodoForm.js'

class App extends Component {
render() {
return (
<div className="App">
<div>
<ToDoListItem
/>
</div>
</div>
);
}
constructor() {
super();
this.state = {
task: []
}
}

handleAdd = (todo) => {
this.state.task.push(todo)
this.setState({ task: this.state.task })
}

handleDelete = (index) => {
this.state.task.splice(index, 1)
this.setState({ task: this.state.task })
}

render() {
var todoItems = this.state.task.map((todo, key) => (
<ToDoListItem
key={key}
title={todo.title}
description={todo.description}
onDelete = { () => this.handleDelete(key) }
/>
))


return (
<div className="App">
<h1> Todo App </h1>
<TodoForm onAdd = { this.handleAdd } />
<div>
{ todoItems }
</div>
</div>
);
}
}

export default App;
16 changes: 10 additions & 6 deletions src/ToDoListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import './ToDoListItem.css';

class ToDoListItem extends Component {
render() {
const {
title,
description
} = this.props;
return (
<div className="ToDoListItem">
<div className="ToDoListItem-title"></div>
<div className="ToDoListItem-description"></div>
</div>
);
}
<div className="ToDoListItem" onClick = { this.props.onDelete }>
<div className="ToDoListItem-title">{ title }</div>
<div className="ToDoListItem-description">{ description }</div>
</div>
);
}
}

export default ToDoListItem;
51 changes: 51 additions & 0 deletions src/TodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { Component } from 'react';
import './App.css';

class TodoForm extends Component {
constructor(props) {
super(props)
this.state = {
title: '',
description: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
var target = event.target;
var name = target.name;
var value = target.value;
this.setState({
[name] : value
});
}
handleSubmit(event) {
this.props.onAdd(this.state);
event.preventDefault()
}

render() {
return (
<div>
<form className="App-form">
<input
type="text"
name="title"
placeholder="Title"
onChange={this.handleChange}
/>
<input
type="text"
name="description"
placeholder="Description"
onChange={this.handleChange}
/>
<button className="button" onClick={this.handleSubmit}>登録</button>
</form>
</div>
);
}
}

export default TodoForm;
Loading