Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94e5dd3

Browse files
committed
added in form
1 parent 8121368 commit 94e5dd3

File tree

5 files changed

+61
-122
lines changed

5 files changed

+61
-122
lines changed

‎app/controllers/api/v1/lists_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create
1919
@list = List.new(list_params)
2020

2121
if @list.save
22-
render json: @list, status: :created,location: @list
22+
render json: @list, status: :created
2323
else
2424
render json: @list.errors, status: :unprocessable_entity
2525
end

‎app/controllers/items_controller.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎app/controllers/lists_controller.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎client/src/components/ListsContainer.jsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import React, { Component } from 'react';
22
import axios from 'axios';
33
import List from './List';
4+
import NewListForm from './NewListForm';
45

56
class ListsContainer extends Component {
6-
constructor(props) {
7-
super(props);
8-
this.state = {
9-
lists: [],
10-
};
11-
}
7+
state = {
8+
lists: [],
9+
};
10+
11+
componentDidMount = () => {
12+
this.loadLists();
13+
};
1214

13-
componentDidMount() {
15+
loadLists=() =>
1416
axios
1517
.get('api/v1/lists.json')
1618
.then(response => {
@@ -20,16 +22,19 @@ class ListsContainer extends Component {
2022
});
2123
})
2224
.catch(error => console.log(error));
23-
}
2425

2526
render() {
2627
const { lists } = this.state;
2728
return (
28-
<div className="lists-container">
29-
{lists.map(list => (
30-
<List list={list} key={list.id} />
31-
))}
32-
</div>
29+
<React.Fragment>
30+
<div className="lists-container">
31+
{lists.map(list => (
32+
<List list={list} key={list.id} />
33+
))}
34+
</div>
35+
36+
<NewListForm onNewList={this.addNewList} />
37+
</React.Fragment>
3338
);
3439
}
3540
}

‎client/src/components/NewListForm.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const NewListForm = ({ onNewList = f => f }) => {
5+
let title;
6+
let excerpt;
7+
const submit = e => {
8+
e.preventDefault();
9+
onNewList(_title.value, _excerpt.value);
10+
title.value = '';
11+
excerpt.value = '';
12+
title.focus();
13+
};
14+
15+
return (
16+
<form onSubmit={submit}>
17+
<input
18+
ref={input => (title = input)}
19+
type="text"
20+
placeholder="Title..."
21+
required
22+
/>
23+
<input
24+
ref={input => (excerpt = input)}
25+
type="text"
26+
placeholder="Excerpt..."
27+
required
28+
/>
29+
<button>Add List</button>
30+
</form>
31+
);
32+
};
33+
34+
NewListForm.propTypes = {
35+
onNewList: PropTypes.func,
36+
};
37+
38+
NewListForm.defaultProps = {
39+
onNewList: () => {},
40+
};
41+
42+
export default NewListForm;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /