Skip to content

Commit 10b6666

Browse files
committed
react first week
1 parent 4025e46 commit 10b6666

File tree

11 files changed

+366
-17
lines changed

11 files changed

+366
-17
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"dependencies": {
66
"react": "^16.9.0",
77
"react-dom": "^16.9.0",
8+
"react-router": "^5.2.0",
9+
"react-router-dom": "^5.2.0",
810
"react-scripts": "3.1.1"
911
},
1012
"scripts": {

src/App.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import React from 'react';
22
import logo from './logo.svg';
33
import './App.css';
4+
import TodoList from './containers/TodoList/TodoList';
5+
import NewTodo from './containers/TodoList/NewTodo/NewTodo'
6+
import { BrowserRouter, Route, Redirect, Switch } from 'react-router-dom'
7+
import TodoDetail from './components/TodoDetail/TodoDetail';
48

59
function App() {
610
return (
7-
<div className="App">
8-
</div>
11+
<BrowserRouter>
12+
<div className="App">
13+
<Switch>
14+
<Route path='/todos' exact render={() => <TodoList title="My TODOs!" />} />
15+
<Route path='/todos/:id' exact component={TodoDetail}/>
16+
<Route path='/new-todo' exact component={NewTodo} />
17+
<Redirect exact from='/' to='/todos' />
18+
<Route render={() => <h1>Not Found</h1>} />
19+
</Switch>
20+
</div>
21+
</BrowserRouter>
922
);
1023
}
11-
1224
export default App;

src/components/Todo/Todo.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.Todo {
2+
border-top: 1px solid #f1f3f5;
3+
padding: 1rem;
4+
display: flex;
5+
align-items: center;
6+
transition: all 0.15s;
7+
}
8+
9+
.Todo .text {
10+
flex: 1;
11+
text-align: left;
12+
word-break: break-all;
13+
cursor: pointer;
14+
}
15+
16+
.Todo .text:hover {
17+
color: orange;
18+
}
19+
20+
.Todo .done {
21+
text-decoration: line-through;
22+
color: #adb5bd;
23+
}
24+
25+
.Todo .done-mark {
26+
font-size: 1.5rem;
27+
line-height: 1rem;
28+
margin-left: 1rem;
29+
color: orange;
30+
font-weight: 800;
31+
}

src/components/Todo/Todo.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import "./Todo.css"
3+
4+
const Todo = props => {
5+
return (
6+
<div className='Todo'>
7+
<div className={`text ${props.done && 'done'}`} onClick={props.clicked}>
8+
{props.title}
9+
</div>
10+
{props.done && <div className='don-mark'>&#x2713;</div>}
11+
</div>
12+
);
13+
};
14+
export default Todo;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.TodoDetail .row {
2+
display: flex;
3+
padding: 20px;
4+
height: 30px;
5+
text-align: left;
6+
}
7+
8+
.TodoDetail .left {
9+
font-weight: bold;
10+
flex: 25%
11+
}
12+
13+
.TodoDetail .right {
14+
flex: 75%;
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import './TodoDetail.css';
3+
4+
const TodoDetail = (props) => {
5+
return (<div className="TodoDetail">
6+
<div className="row">
7+
<div className="left">
8+
Name:
9+
</div>
10+
<div className="right">
11+
{props.title}
12+
</div>
13+
</div>
14+
<div className="row">
15+
<div className="left">
16+
Content:
17+
</div>
18+
<div className="right">
19+
{props.content}
20+
</div>
21+
</div>
22+
</div>
23+
);
24+
};
25+
export default TodoDetail;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.NewTodo {
2+
width: 80%;
3+
margin: 20px auto;
4+
border: 1px solid #eee;
5+
box-shadow: 0 2px 3px #ccc;
6+
text-align: center;
7+
}
8+
9+
.NewTodo label {
10+
display: block;
11+
margin: 10px auto;
12+
text-align: center;
13+
font-weight: bold;
14+
}
15+
16+
.NewTodo input,
17+
.NewTodo textarea {
18+
display: block;
19+
width: 80%;
20+
box-sizing: border-box;
21+
border: 1px solid black;
22+
outline: none;
23+
font: inherit;
24+
margin: auto;
25+
}
26+
27+
.NewTodo button {
28+
margin: 5px 0;
29+
padding: 10px;
30+
font: inherit;
31+
border: 1px solid #fa923f;
32+
background-color: transparent;
33+
color: #fa923f;
34+
cursor: pointer;
35+
}
36+
37+
.NewTodo button:hover,
38+
.NewTodo button:active {
39+
color: white;
40+
background-color: #fa923f;
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { Component } from 'react';
2+
import { Redirect } from 'react-router-dom'
3+
import './NewTodo.css';
4+
5+
class NewTodo extends Component {
6+
state = {
7+
title: '',
8+
content: '',
9+
submitted: false,
10+
}
11+
12+
postTodoHandler = () => {
13+
const data =
14+
{ title: this.state.title, content: this.state.content };
15+
alert('Submitted\n' + data.title + '\n' + data.content);
16+
this.setState( {submitted: true} );
17+
this.props.history.push('/todos');
18+
}
19+
20+
render() {
21+
if (this.state.submitted) {
22+
return <Redirect to='/todos' />
23+
}
24+
return (
25+
<div className="NewTodo">
26+
<h1>Add a Todo</h1>
27+
<label>Title</label>
28+
<input type="text" value={this.state.title}
29+
onChange={(event) => this.setState({ title: event.target.value })} />
30+
<label>Content</label>
31+
<textarea rows="4" type="text" value={this.state.content}
32+
onChange={(event) => this.setState({ content: event.target.value })} />
33+
<button onClick={() => this.postTodoHandler()}>Submit</button>
34+
</div>
35+
);
36+
}
37+
};
38+
export default NewTodo;

src/containers/TodoList/TodoList.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.TodoList {
2+
background: white;
3+
width: 512px;
4+
box-shadow: 0 3px 9px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); /* 그림자 */
5+
margin: auto;
6+
margin-top: 4rem;
7+
}
8+
9+
.TodoList .title {
10+
padding: 2rem;
11+
font-size: 2.5rem;
12+
text-align: center;
13+
font-weight: 500;
14+
background: orange;
15+
color: black;
16+
}

src/containers/TodoList/TodoList.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, {Component} from 'react';
2+
import Todo from '../../components/Todo/Todo';
3+
import TodoDetail from '../../components/TodoDetail/TodoDetail';
4+
import { NavLink } from 'react-router-dom';
5+
import NewTodo from './NewTodo/NewTodo';
6+
import "./TodoList.css"
7+
8+
class TodoList extends Component {
9+
state = {
10+
todos: [
11+
{id: 1, title: 'SWPP', content: 'take swpp class', done: true},
12+
{id: 2, title: 'Movie', content: 'watch movie', done: false},
13+
{id: 3, title: 'Dinner', content: 'eat dinner', done: false},
14+
],
15+
selectedTodo: null,
16+
}
17+
18+
clickTodoHandler = td => {
19+
if (this.state.selectedTodo === td) {
20+
this.setState({selectedTodo: null});
21+
} else {
22+
this.setState({selectedTodo: td});
23+
}
24+
}
25+
26+
render() {
27+
const todos = this.state.todos.map((td) => {
28+
return ( <Todo key={td.id} title={td.title}
29+
done={td.done} clicked={() => this.clickTodoHandler(td)}/> );
30+
});
31+
let todoDetail = null;
32+
if (this.state.selectedTodo) {
33+
todoDetail = <TodoDetail title={this.state.selectedTodo.title}
34+
content={this.state.selectedTodo.content} />
35+
}
36+
return (
37+
<div className='TodoList'>
38+
<div className='title'>{this.props.title}</div>
39+
<div className='todos'>{todos}</div>
40+
{todoDetail}
41+
<NavLink to='new-todo' exact>New Todo</NavLink>
42+
</div>
43+
);
44+
}
45+
46+
47+
48+
49+
}
50+
export default TodoList;

0 commit comments

Comments
 (0)