This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
[2주차] 최승원 미션 제출합니다. #4
Open
seungwon2
wants to merge
15
commits into
CEOS-Developers:master
Choose a base branch
from
seungwon2:wonwon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bd8ba01
todo-input 프론트 기본완성
seungwon2 2a02c2c
프론트 구성 완성
seungwon2 75737fa
hooks사용해서 value저장하기
seungwon2 ae7c343
등록 시 todo 완료
seungwon2 167d79d
컴포넌트 연결, 404에러
seungwon2 f347be2
배열 구성 수정
seungwon2 58b9f5f
alert 설정
seungwon2 d974eba
alert 완성
seungwon2 224f5fa
complete 작업
seungwon2 b490c45
완료 오류 수정
seungwon2 43902fa
split 에러 수정
seungwon2 07cfe0b
readme추가
seungwon2 5a6f980
style initial, none 불필요한 코드 삭제
seungwon2 1bb4499
style border 속성 합치기
seungwon2 4240c7d
validate check 함수 분리, Flag삭제
seungwon2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,5 @@ yarn-error.log* | |
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| .now | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"orgId":"vC0ivr1sq0T0zKJytpWAmdFN","projectId":"QmU68M4LipQZeiFKBEhK7WmUX9o8wjXK3RGeuiZ8PSWDDK"} | ||
| {"orgId":"Zo3Q3h9F77k7oPOVf5QNEp0q","projectId":"QmVYdcpYkTHLrGcnjr7PaRHw7HPc4ufUWHRCmRJ8W5de6H"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,22 @@ | ||
| # react-todo-11th | ||
|
|
||
| ## 실행 방법 | ||
| ## 구성 파악 | ||
|
|
||
| ``` | ||
| npm install | ||
| npm run dev | ||
| ``` | ||
| 1. 첫 화면에 날짜와 업무를 입력하는 부분이 있다 | ||
| 2. 날짜와 업무를 입력하면 오른쪽에 투두 리스트가 쌓인다 | ||
| 3. 투두 리스트에는 완료 버튼이 있고, 완료 버튼을 누르면 해당 업무가 사라진다. | ||
| 4. 투두 입력과 제출시 alert으로 정해진 값 입력을 안내한다. | ||
|
|
||
| - npm install : 필요한 모든 패키지를 설치합니다. 처음 1번만 실행하면 됩니다. | ||
| - npm run dev : react 어플리케이션을 브라우저에서 실행합니다. | ||
| ## 구현 방법 | ||
|
|
||
| ## 배포 방법 | ||
| 1. 프론트 구성(배경색, 글자크기와 색 및 위치 등) 완성 | ||
| 2. index에 투두 배열 생성 후 값을 받아오고, 뿌린다 | ||
| 3. index에서 TodoInput부분과 TodoList부분을 구성해놓는다 | ||
| 4. TodoInput에서 받아온 배열을 TodoList로 보낸다 | ||
| 5. TodoList에서 배열을 map으로 파싱하여 TodoItem으로 보내 내용을 띄운다 | ||
| 6. TodoItem에서 완료 클릭 시 index에서 해당 배열을 id값으로 삭제한다 | ||
|
|
||
| - now에 회원가입하고 now를 설치합니다. | ||
| ## 어려웠던 점 | ||
|
|
||
| 1. https://zeit.co 에서 회원가입합니다. | ||
| 2. 터미널에서 npm i -g now를 입력해 now를 글로벌로 설치합니다. | ||
| 3. 명령 프롬프트에서 프로젝트 폴더에 들어간 후 now를 입력합니다. | ||
| 4. ID/PW를 입력합니다. | ||
| 5. zeit 가입시 입력한 이메일에서 인증 링크를 클릭합니다. <인증완료> | ||
| 6. 다시 프로젝트 폴더에서 now를 입력하면 자동으로 생성된 url에 배포됩니다! | ||
|
|
||
| ## 미션 설명 | ||
|
|
||
| [미션 설명](./docs/mission-description/README.md) | ||
|
|
||
| ## 미션 제출 방법 | ||
|
|
||
| [미션 제출 방법](./docs/how-to-submit/README.md) | ||
| 1. useState을 이용해 배열을 할당해본 경험이 없어서 원하는대로 배열 내부를 구성해서 사용하기까지 어려움이 있었습니다. | ||
| 2. class형이 아닌 함수형으로 구현한 react에서 TodoItem에서 id값을 끌어오는 것이 조금 힘들었습니다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,93 @@ | ||
| import React from "react"; | ||
| import styled from "styled-components"; | ||
|
|
||
| export default function TodoInput() { | ||
| export default function TodoInput({ | ||
| date, | ||
| task, | ||
| addTodo, | ||
| onChangeDate, | ||
| onChangeTask, | ||
| }) { | ||
| return ( | ||
| <Wrapper> | ||
| 리액트-투두 | ||
| <br /> | ||
| 시간을 입력하는 칸 | ||
| <br /> | ||
| Todo를 입력하는 칸 | ||
| <DateInput> | ||
| <DateLabel>날짜</DateLabel> | ||
| <DateInputArea | ||
| placeholder="날짜를 입력하세요 (ex.20200404)" | ||
| type="number" | ||
| value={date} | ||
| onChange={onChangeDate} | ||
| /> | ||
| </DateInput> | ||
| <TaskInput> | ||
| <TodoLabel>TODO</TodoLabel> | ||
| <TaskTextArea | ||
| placeholder="할 일을 입력하세요" | ||
| value={task} | ||
| onChange={onChangeTask} | ||
| /> | ||
| </TaskInput> | ||
| <Submit onClick={addTodo}>등록</Submit> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
|
|
||
| const Submit = styled.button` | ||
| color: white; | ||
| background-color: rgb(97, 97, 97); | ||
| font-size: 1.5rem; | ||
| outline: none; | ||
| border-style: none; | ||
| padding: 0.5rem 1rem; | ||
| border-radius: 0.3rem; | ||
| `; | ||
| const DateLabel = styled.p` | ||
| font-size: 1.5rem; | ||
| padding: 0px; | ||
| margin: 0px; | ||
| `; | ||
| const DateInputArea = styled.input` | ||
| width: 80%; | ||
| border: 1px solid rgb(97, 97, 97); | ||
| padding: 0.5rem 0.8rem; | ||
| `; | ||
| const TodoLabel = styled.p` | ||
| font-size: 1.5rem; | ||
| padding: 0px; | ||
| margin: 0px; | ||
| `; | ||
| const TaskTextArea = styled.textarea` | ||
| width: 80%; | ||
| height: 30vh; | ||
| resize: none; | ||
| border: 1px solid rgb(97, 97, 97); | ||
| padding: 0.5rem 0.8rem; | ||
| `; | ||
| const DateInput = styled.div` | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| align-items: flex-start; | ||
| margin-bottom: 3rem; | ||
| `; | ||
|
|
||
| const TaskInput = styled.div` | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: row; | ||
| 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; | ||
| align-items: center; | ||
| height: 37rem; | ||
| flex: 1 1 0%; | ||
| border: 1px solid black; | ||
| padding: 1rem 2rem; | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,46 @@ | ||
| import React from "react"; | ||
| import styled from "styled-components"; | ||
|
|
||
| export default function TodoItem() { | ||
| return <Wrapper>Todo</Wrapper>; | ||
| export default function TodoItem({ id, task, date, onClickComplete }) { | ||
| return ( | ||
| <Wrapper> | ||
| <TodoContents>{task}</TodoContents> | ||
| <CompleteSection> | ||
| {date} | ||
| <Complete onClick={() => onClickComplete(id)}>완료</Complete> | ||
| </CompleteSection> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
|
|
||
| const Complete = styled.button` | ||
| color: white; | ||
| background-color: rgb(97, 97, 97); | ||
| font-size: 1.5rem; | ||
| outline: none; | ||
| padding: 0.5rem 1rem; | ||
| border-radius: 0.3rem; | ||
| `; | ||
| const CompleteSection = styled.p` | ||
| font-size: 1.5rem; | ||
| display: flex; | ||
| flex-direction: column; | ||
| padding: 0px; | ||
| margin: 0px; | ||
| `; | ||
| const TodoContents = styled.p` | ||
| font-size: 1.5rem; | ||
| display: flex; | ||
| flex-direction: column; | ||
| padding: 0px; | ||
| margin: 0px; | ||
| `; | ||
| const Wrapper = styled.div` | ||
| font-size: 18px; | ||
| border: solid 1px; | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| align-items: flex-start; | ||
| margin-bottom: 3rem; | ||
| padding: 1rem 2rem; | ||
| border: 1px solid rgb(97, 97, 97); | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,30 +1,98 @@ | ||||||||
| import React from "react"; | ||||||||
| import React, { useState } from "react"; | ||||||||
|
|
||||||||
| import TodoInput from "../components/todo-input"; | ||||||||
| import TodoList from "../components/todo-list"; | ||||||||
|
|
||||||||
| import styled from "styled-components"; | ||||||||
|
|
||||||||
| export default function Home() { | ||||||||
| const [date, setDate] = useState(); | ||||||||
| const [task, setTask] = useState(); | ||||||||
| const [todos, setTodoList] = useState([]); | ||||||||
|
|
||||||||
| const onChangeTask = (e) => { | ||||||||
| setTask(e.target.value); | ||||||||
| }; | ||||||||
| const onChangeDate = (e) => { | ||||||||
| setDate(e.target.value); | ||||||||
| }; | ||||||||
|
|
||||||||
| const stateReset = (e) => { | ||||||||
| setDate(""); | ||||||||
| setTask(""); | ||||||||
| }; | ||||||||
|
|
||||||||
| const validateTodo = () => { | ||||||||
| let isValid = false; | ||||||||
| let isDateValid = date.length === 8 && date > 20200101; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| let isTaskValid = task.length > 0; | ||||||||
| if (!isDateValid) { | ||||||||
| alert("날짜를 올바른 형식으로 입력해주세요!"); | ||||||||
| } else if (!isTaskValid) { | ||||||||
| alert("모든 항목을 입력해주세요!"); | ||||||||
| } | ||||||||
| isValid = isDateValid && isTaskValid; | ||||||||
| return isValid; | ||||||||
|
Comment on lines
+34
to
+35
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
불필요힌 코드는 합쳐주세용~ |
||||||||
| }; | ||||||||
|
|
||||||||
| const addTodo = (e) => { | ||||||||
| if (!validateTodo()) return; | ||||||||
| setTodoList([ | ||||||||
| ...todos, | ||||||||
| { | ||||||||
| id: todos.length, | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 id는 unique key 역할을 할 수 없어요! |
||||||||
| date, | ||||||||
| task, | ||||||||
| }, | ||||||||
| ]); | ||||||||
| stateReset(e); | ||||||||
| alert("입력 완료!"); | ||||||||
| }; | ||||||||
|
|
||||||||
| const onClickComplete = (id) => { | ||||||||
| const newTodos = [...todos]; | ||||||||
| setTodoList(newTodos.filter((todo) => todo.id !== id)); | ||||||||
| console.log(newTodos); | ||||||||
| }; | ||||||||
|
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 완료 버튼 누르면 삭제하는 함수인 거 같네요. 이 함수는 todo-item.js에서 정의해서 사용하면 좋을 거 같아요! |
||||||||
|
|
||||||||
| return ( | ||||||||
| <Wrapper> | ||||||||
| <Title>리액트-투두</Title> | ||||||||
| <Contents> | ||||||||
| <TodoInput /> | ||||||||
| <TodoList /> | ||||||||
| <TodoInput | ||||||||
| date={date} | ||||||||
| task={task} | ||||||||
| onChangeDate={onChangeDate} | ||||||||
| onChangeTask={onChangeTask} | ||||||||
| todos={todos} | ||||||||
| addTodo={addTodo} | ||||||||
| /> | ||||||||
| <BlankSpace /> | ||||||||
| <TodoList todos={todos} onClickComplete={onClickComplete} /> | ||||||||
| </Contents> | ||||||||
| </Wrapper> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| const BlankSpace = styled.div` | ||||||||
| flex: 0.3; | ||||||||
| `; | ||||||||
| const Title = styled.p` | ||||||||
| font-size: 3rem; | ||||||||
| font-weight: 600; | ||||||||
| padding: 0px; | ||||||||
| margin: 0px 0px 3rem; | ||||||||
| `; | ||||||||
| const Wrapper = styled.div` | ||||||||
| height: 100vh; | ||||||||
| min-height: 100vh; | ||||||||
| background-color: rgb(155, 197, 195); | ||||||||
| padding: 4rem 5rem; | ||||||||
| font-size: 0.1rem; | ||||||||
| color: white; | ||||||||
| `; | ||||||||
|
|
||||||||
| const Contents = styled.div` | ||||||||
| border: solid 1px black; | ||||||||
| display: flex; | ||||||||
| flex-direction: row; | ||||||||
| justify-content: space-between; | ||||||||
| padding: 10px 20px; | ||||||||
| margin: 20px 10px; | ||||||||
| `; | ||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
date와 task state는 입력받을 때만 사용되고 입력이 끝나면 리셋되는 state인 것 같네요. 실제로 사용되는 부분 외에서 state를 정의하여 사용하다 보면 불필요한 리렌더가 발생할 수 있어서, date와 task는 todo-input.js에서 state관리를 해주는 게 좋을 것 같아요.