From 3aacd813dafcc50911133f10a8fdc64c0fcab63c Mon Sep 17 00:00:00 2001 From: arclic Date: Thu, 16 Sep 2021 23:12:07 +0900 Subject: [PATCH] Practice session 3 --- package.json | 2 + src/App.js | 28 ++++-- src/components/Todo/Todo.js | 16 ++++ src/components/TodoDetail/TodoDetail.js | 26 ++++++ src/containers/TodoList/NewTodo/NewTodo.js | 48 +++++++++++ src/containers/TodoList/TodoList.js | 61 +++++++++++++ yarn.lock | 99 +++++++++++++++++++++- 7 files changed, 272 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index bcaefee..c212d75 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "dependencies": { "react": "^17.0.2", "react-dom": "^17.0.2", + "react-router": "^5.2.0", + "react-router-dom": "^5.2.0", "react-scripts": "4.0.3" }, "scripts": { diff --git a/src/App.js b/src/App.js index e358583..761cd0c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,11 +1,29 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React from "react"; +import "./App.css"; + +import TodoList from "./containers/TodoList/TodoList"; +import TodoDetail from "./components/TodoDetail/TodoDetail"; +import NewTodo from "./containers/TodoList/NewTodo/NewTodo"; + +import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom"; function App() { return ( -
-
+ +
+ + } + /> + + + +

Not Found

} /> +
+
+
); } diff --git a/src/components/Todo/Todo.js b/src/components/Todo/Todo.js index e69de29..e41c514 100644 --- a/src/components/Todo/Todo.js +++ b/src/components/Todo/Todo.js @@ -0,0 +1,16 @@ +import React from "react"; + +import "./Todo.css"; + +const Todo = (props) => { + return ( +
+
+ {props.title} +
+ {props.done &&
} +
+ ); +}; + +export default Todo; diff --git a/src/components/TodoDetail/TodoDetail.js b/src/components/TodoDetail/TodoDetail.js index e69de29..4a43109 100644 --- a/src/components/TodoDetail/TodoDetail.js +++ b/src/components/TodoDetail/TodoDetail.js @@ -0,0 +1,26 @@ +import React from "react"; + +import "./TodoDetail.css"; + +class TodoDetail extends React.Component { + render() { + if (this.props.match) { + console.log(this.props.match.params.id); + } + return ( +
+
+
Name:
+
{this.props.title}
+
+ +
+
Content:
+
{this.props.content}
+
+
+ ); + } +} + +export default TodoDetail; diff --git a/src/containers/TodoList/NewTodo/NewTodo.js b/src/containers/TodoList/NewTodo/NewTodo.js index e69de29..d68e7a1 100644 --- a/src/containers/TodoList/NewTodo/NewTodo.js +++ b/src/containers/TodoList/NewTodo/NewTodo.js @@ -0,0 +1,48 @@ +import React, { Component } from "react"; + +import { Redirect } from "react-router-dom"; + +import "./NewTodo.css"; + +class NewTodo extends Component { + state = { + title: "", + content: "", + submitted: false, + }; + + postTodoHandler = () => { + const data = { title: this.state.title, content: this.state.content }; + alert("Submitted\n" + data.title + "\n" + data.content); + this.setState({ submitted: true }); + }; + + render() { + let redirect = null; + if (this.state.submitted) { + redirect = ; + } + return ( +
+ {redirect} +

Add a Todo

+ + this.setState({ title: event.target.value })} + /> + +