Skip to content

Commit b41884b

Browse files
Create Process Finish
1 parent 0926b35 commit b41884b

File tree

8 files changed

+152
-7
lines changed

8 files changed

+152
-7
lines changed

public/pure.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ <h1>WEB</h1>
1616
<li><a href="3.html">JavaScript</a></li>
1717
</ul>
1818
</nav>
19-
19+
<div>
20+
<a href="/create">create</a><br>
21+
<a href="/update">update</a><br>
22+
<button>delete</button>
23+
</div>
24+
<hr>
2025
<article>
2126
<h2>HTML</h2>
2227
<p>Its HTML</p>

src/App.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, { Component } from 'react';
22
import Header from './components/Header';
33
import Navigation from './components/Navigation';
4-
import Article from './components/Article';
4+
import ReadArticle from './components/ReadArticle';
5+
import CreateArticle from './components/CreateArticle';
6+
import Control from './components/Control';
57
import './App.css';
68

79
class App extends React.Component {
810
constructor(props){
911
super(props);
12+
this.max_index = 3;
1013
this.state = {
1114
mode: 'Welcome',
1215
subject: {
@@ -41,18 +44,35 @@ class App extends React.Component {
4144
}
4245

4346
render() {
44-
let _title, _desc;
47+
let _title, _desc, _article;
4548
if(this.state.mode === 'Welcome'){
4649
_title = this.state.Welcome.title;
4750
_desc = this.state.Welcome.description;
48-
} else {
51+
_article = <ReadArticle title={_title} description={_desc}></ReadArticle>;
52+
} else if(this.state.mode === 'Read'){
4953
for(let i = 0; i<this.state.contents.length; i++){
5054
if(this.state.contents[i].id === this.state.selected_contents){
5155
_title = this.state.contents[i].title;
5256
_desc = this.state.contents[i].description;
5357
break;
5458
}
5559
}
60+
_article = <ReadArticle title={_title} description={_desc}></ReadArticle>;
61+
} else if(this.state.mode === 'Create'){
62+
_article = <CreateArticle onCreate={function(_title, _desc){
63+
this.max_index = this.max_index + 1;
64+
const newArticle = {
65+
id: this.max_index,
66+
title: _title,
67+
description: _desc
68+
};
69+
const grpArticle = this.state.contents.concat(newArticle);
70+
this.setState(
71+
{
72+
contents: grpArticle
73+
}
74+
);
75+
}.bind(this)}></CreateArticle>
5676
}
5777
return (
5878
<div className="App">
@@ -78,8 +98,18 @@ class App extends React.Component {
7898
);
7999
}.bind(this)}
80100
></Navigation>
101+
<Control
102+
mode={this.state.mode}
103+
onChangePage={function(_mode){
104+
this.setState(
105+
{
106+
mode: _mode
107+
}
108+
)
109+
}.bind(this)}
110+
></Control>
81111
<hr></hr>
82-
<Article title={_title} description={_desc}></Article>
112+
{_article}
83113
</div>
84114
);
85115
}

src/components/Control.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { Component } from 'react';
2+
import CreateControl from './CreateControl';
3+
import UpdateControl from './UpdateControl';
4+
import DeleteControl from './DeleteControl';
5+
6+
class Control extends Component {
7+
render() {
8+
let _createControl, _updateControl, _deleteControl;
9+
if(this.props.mode === 'Welcome'){
10+
_createControl = <CreateControl onChangePage={this.props.onChangePage}></CreateControl>;
11+
_updateControl = '';
12+
_deleteControl = '';
13+
} else if(this.props.mode === 'Read'){
14+
_createControl = '';
15+
_updateControl = <UpdateControl onChangePage={this.props.onChangePage}></UpdateControl>;
16+
_deleteControl = <DeleteControl onChangePage={this.props.onChangePage}></DeleteControl>;
17+
} else {
18+
_createControl = '';
19+
_updateControl = '';
20+
_deleteControl = '';
21+
}
22+
23+
return (
24+
<div>
25+
{_createControl}
26+
{_updateControl}
27+
{_deleteControl}
28+
</div>
29+
);
30+
}
31+
}
32+
33+
export default Control;

src/components/CreateArticle.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Component } from 'react';
2+
3+
class CreateArticle extends Component {
4+
render() {
5+
return (
6+
<article>
7+
<h2>Create</h2>
8+
<div>
9+
<form
10+
action="/process_create"
11+
onSubmit={function(event){
12+
event.preventDefault();
13+
const _title = event.target.title.value;
14+
const _desc = event.target.description.value;
15+
this.props.onCreate(_title, _desc);
16+
}.bind(this)}>
17+
<input type="text" name="title" placeholder="title"></input><br></br>
18+
<textarea name="description" placeholder="description"></textarea><br></br>
19+
<input type="submit" value="OK"></input>
20+
</form>
21+
</div>
22+
</article>
23+
);
24+
}
25+
}
26+
27+
export default CreateArticle;

src/components/CreateControl.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { Component } from 'react';
2+
3+
class CreateControl extends Component {
4+
render() {
5+
return (
6+
<a
7+
href="/create"
8+
onClick={function(event){
9+
event.preventDefault();
10+
this.props.onChangePage('Create');
11+
}.bind(this)}
12+
>create</a>
13+
);
14+
}
15+
}
16+
17+
export default CreateControl;

src/components/DeleteControl.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { Component } from 'react';
2+
3+
class DeleteControl extends Component {
4+
render() {
5+
return (
6+
<button
7+
onClick={function(event){
8+
event.preventDefault();
9+
this.props.onChangePage('Delete');
10+
}.bind(this)}
11+
>delete</button>
12+
);
13+
}
14+
}
15+
16+
export default DeleteControl;

src/components/Article.js renamed to src/components/ReadArticle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22

3-
class Article extends Component {
3+
class ReadArticle extends Component {
44
render() {
55
return (
66
<article>
@@ -11,4 +11,4 @@ class Article extends Component {
1111
}
1212
}
1313

14-
export default Article;
14+
export default ReadArticle;

src/components/UpdateControl.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { Component } from 'react';
2+
3+
class UpdateControl extends Component {
4+
render() {
5+
return (
6+
<a
7+
href="/update"
8+
onClick={function(event){
9+
event.preventDefault();
10+
this.props.onChangePage('Update');
11+
}.bind(this)}
12+
>update</a>
13+
);
14+
}
15+
}
16+
17+
export default UpdateControl;

0 commit comments

Comments
 (0)