From bd9e0a2b879f08d0f3d1025906860b00942e10e9 Mon Sep 17 00:00:00 2001 From: seabstianjeong Date: Thu, 9 Apr 2020 00:55:18 +0900 Subject: [PATCH 1/5] change body font color --- pages/_app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/_app.js b/pages/_app.js index 3051a08..f85a8d2 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -23,6 +23,7 @@ class PickkApp extends App { font-size: 0.1rem; overflow-x: hidden; width: 100%; + color: white; } ::-webkit-scrollbar { display: none; From 7798aada17b18e916cd0b04e61614fc70bc00e5c Mon Sep 17 00:00:00 2001 From: seabstianjeong Date: Thu, 9 Apr 2020 00:55:31 +0900 Subject: [PATCH 2/5] Modify index.js --- pages/index.js | 68 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/pages/index.js b/pages/index.js index f494909..fdef5eb 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import TodoInput from "../components/todo-input"; import TodoList from "../components/todo-list"; @@ -6,25 +6,73 @@ import TodoList from "../components/todo-list"; import styled from "styled-components"; export default function Home() { + const [todos, setTodos] = useState([ + ]) + + const [counter, setCounter] = useState(1) // todo 샘플 지울때 0으로 바꾸기. + + // todo 추가하기 + const addTodo = ({ content, dueDate }) => { + // check whether every input is filled + if ((content === undefined) || (dueDate === undefined)) { + alert('모든 항목을 입력해주세요!'); + return; + } + + // check whether dueDate is valid + const dateRegExp = /^\d{8}$/; + if (!dateRegExp.exec(dueDate)) { + alert('날짜를 올바른 형식으로 입력해주세요!'); + return; + } + + // add todo to todos + // increment counter + setCounter(counter + 1); + setTodos([ + ...todos, + { id: counter, content, dueDate, isComplete: false } + ]) + + alert('입력 완료!') + } + + // todo 완료하기 + const completeTodo = (id) => { + setTodos( + todos.map((todo) => todo.id === id ? { ...todo, isComplete: true } : todo) + ) + } + return ( + 리액트-투두 - - + +
+
+
CEOS 11기 정시원
); } const Wrapper = styled.div` - height: 100vh; + min-height: 100vh; + background-color: rgb(155, 197, 195); + padding: 4rem 5rem; `; const Contents = styled.div` - border: solid 1px black; - display: flex; - flex-direction: row; - justify-content: space-between; - padding: 10px 20px; - margin: 20px 10px; + display: flex; + flex-direction: row; + -webkit-box-pack: justify; + justify-content: space-between; `; + +const Title = styled.p` + font-size: 3rem; + font-weight: 600; + padding: 0px; + margin: 0px 0px 3rem; +` \ No newline at end of file From a3ce4cb9edc60d76b97b2ae929bb74dba40b6ff2 Mon Sep 17 00:00:00 2001 From: seabstianjeong Date: Thu, 9 Apr 2020 00:55:40 +0900 Subject: [PATCH 3/5] Modify todo-list.js --- components/todo-list.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/components/todo-list.js b/components/todo-list.js index 68fded1..fc87d77 100644 --- a/components/todo-list.js +++ b/components/todo-list.js @@ -3,17 +3,17 @@ import styled from "styled-components"; import TodoItem from "./todo-item"; -export default function TodoList() { - return ( - - Todo list가 들어가는 자리입니다! - - - ); +export default function TodoList({ todos, completeTodo }) { + return ( + + {todos.sort((todo1, todo2) => { + return todo1.dueDate < todo2.dueDate ? -1 : todo1.dueDate > todo2.dueDate ? 1 : 0; + }).map((todo) => (todo.isComplete ? null : ))} + + ); } const Wrapper = styled.div` - border: solid 1px; - font-size: 18px; - flex: 1; + font-size: 18px; + flex: 1 1 0%; `; From a42e455609afd0bf5865efa34bf849d5429903ce Mon Sep 17 00:00:00 2001 From: seabstianjeong Date: Thu, 9 Apr 2020 00:55:52 +0900 Subject: [PATCH 4/5] Modify todo-input.js --- components/todo-input.js | 82 ++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/components/todo-input.js b/components/todo-input.js index 1844e25..b3be4c0 100644 --- a/components/todo-input.js +++ b/components/todo-input.js @@ -1,20 +1,72 @@ -import React from "react"; +import React, { useState } from "react"; import styled from "styled-components"; -export default function TodoInput() { - return ( - - 리액트-투두 -
- 시간을 입력하는 칸 -
- Todo를 입력하는 칸 -
- ); +export default function TodoInput({ addTodo }) { + const [thisTodo, setThisTodo] = useState({ + }) + + const inputChangeHandler = (el) => { + const { name, value } = el.target; + + if (name === 'dueDate') { + if (value.length > 8) { + el.target.value = value.slice(0, 8); + return; + } + } + + setThisTodo({ + ...thisTodo, + [name]: value + }) + } + + return ( + + +

시간

+ +
+ +

TODO

+ +
+ +
+ ); } +const TimeInput = styled.div` + width: 100%; + display: flex; + flex-direction: row; + -webkit-box-pack: justify; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 3rem;` + +const ContentInput = styled.div` + width: 100%; + display: flex; + flex-direction: row; + -webkit-box-pack: justify; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 3rem;` + const Wrapper = styled.div` - border: solid 1px; - font-size: 18px; - flex: 1; -`; + width: 100%; + display: flex; + flex-direction: column; + -webkit-box-align: center; + align-items: center; + height: 37rem; + flex: 1 1 0%; + border-width: 1px; + border-style: solid; + border-color: black; + border-image: initial; + padding: 1rem 2rem; +`; \ No newline at end of file From 5732243e673513a8804b4c3148aaa19ff697f477 Mon Sep 17 00:00:00 2001 From: seabstianjeong Date: Thu, 9 Apr 2020 00:56:02 +0900 Subject: [PATCH 5/5] Modify todo-item.js --- components/todo-item.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/components/todo-item.js b/components/todo-item.js index ef2dbe8..2c9b120 100644 --- a/components/todo-item.js +++ b/components/todo-item.js @@ -1,11 +1,34 @@ import React from "react"; import styled from "styled-components"; -export default function TodoItem() { - return Todo; +function TodoItem({ id, content, dueDate, completeTodo }) { + return +

{content}

+

{dueDate} + +

+
; } const Wrapper = styled.div` - font-size: 18px; - border: solid 1px; + width: 100%; + display: flex; + flex-direction: row; + -webkit-box-pack: justify; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 3rem; + padding: 1rem 2rem; + border-width: 1px; + border-style: solid; + border-color: black; + border-image: initial; `; + +const areEqual = (prevProps, nextProps) => { + return prevProps.id === nextProps.id; +} + +export default React.memo(TodoItem, areEqual); \ No newline at end of file