-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2주차] 최민주 미션 제출합니다. #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body{ | ||
background-color: black; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,180 @@ | ||||||
import {React, useState} from 'react' | ||||||
import './App.css' | ||||||
import styled from 'styled-components'; | ||||||
import TodoInput from "./components/TodoInput.js"; | ||||||
import TodoList from "./components/TodoList.js"; | ||||||
import DoneList from "./components/DoneList.js"; | ||||||
let getId = 1; | ||||||
|
||||||
const Container = styled.div` | ||||||
background-color: black; | ||||||
width: 30rem; | ||||||
margin: auto; | ||||||
height: 50rem; | ||||||
border-style: solid; | ||||||
border-radius: 2%; | ||||||
border-color: white; | ||||||
` | ||||||
|
||||||
const Title = styled.div` | ||||||
width: 90%; | ||||||
margin-left: 5%; | ||||||
margin-top: 3rem; | ||||||
margin-bottom: 1.5rem; | ||||||
Comment on lines
+21
to
+23
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.
|
||||||
height: 5vh; | ||||||
color: white; | ||||||
font-size: 30px; | ||||||
text-align: center; | ||||||
font-weight: 800; | ||||||
|
||||||
border-bottom: solid; | ||||||
border-radius: 2%; | ||||||
` | ||||||
|
||||||
const TodoTitle = styled. div` | ||||||
width: 82%; | ||||||
height: 32px; | ||||||
color: white; | ||||||
font-size: 28px; | ||||||
text-align: left; | ||||||
font-weight: bold; | ||||||
margin-left : 15%; | ||||||
margin-top : 1.5rem; | ||||||
margin-bottom: 4px; | ||||||
display: flex; | ||||||
` | ||||||
const DoneTitle = styled. div` | ||||||
width: 82%; | ||||||
height: 32px; | ||||||
color: white; | ||||||
font-size: 28px; | ||||||
text-align: left; | ||||||
font-weight: bold; | ||||||
margin-left : 15%; | ||||||
margin-top : 1.5rem; | ||||||
margin-bottom: 4px; | ||||||
display: flex; | ||||||
Comment on lines
+34
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. 현재 +) 밑에 있는 컴포넌트들도 중복된게 많아보이는데 하나의 컴포넌트로 사용해주세요! |
||||||
` | ||||||
const TodoBox = styled.div` | ||||||
position: relative; | ||||||
width: 82%; | ||||||
height: 30%; | ||||||
margin-left: 8%; | ||||||
margin-top: 1rem; | ||||||
` | ||||||
Comment on lines
+58
to
+64
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. 할 일의 개수가 box 크기보다 많아졌을 경우 처리가 안되어서 밑의 영역까지 넘어가게 되는데, |
||||||
|
||||||
const DoneBox = styled.div` | ||||||
position: relative; | ||||||
width: 82%; | ||||||
height: 30%; | ||||||
margin-left: 8%; | ||||||
margin-top: 1rem; | ||||||
` | ||||||
const TodoRldBtn = styled.button` | ||||||
margin-left: 50%; | ||||||
border: none; | ||||||
width: 60px; | ||||||
font-size : 25px; | ||||||
background-color : black; | ||||||
` | ||||||
const DoneRldBtn = styled.button` | ||||||
margin-left: 50%; | ||||||
border: none; | ||||||
width: 60px; | ||||||
font-size : 25px; | ||||||
background-color : black; | ||||||
` | ||||||
|
||||||
function App() { | ||||||
const [todos, setTodos] = useState([]); | ||||||
const addTodoList = (text) => { | ||||||
if (text === ""){ //trim 나중에 적용시키기 | ||||||
return alert("입력된 내용이 없습니다."); | ||||||
} else{ | ||||||
const todo = { | ||||||
id: getId, | ||||||
text, | ||||||
checked: false | ||||||
} | ||||||
setTodos(todos => todos.concat(todo)); | ||||||
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. concat 함수보다 push나 ...(spread) 연산자를 사용하시는 것도 좋을 것 같아요!! 이것도 문기님 코드 리뷰 보고 알았습니당!! 참고하시면 좋을 것 같아요💪🏻💪🏻 코드 리뷰 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. 예지님 말씀처럼 spread(...) 연산자를 사용하는 게 좋을 것 같아요!
Suggested change
|
||||||
getId++; | ||||||
} | ||||||
}; | ||||||
const [dones, setDones] = useState([]); | ||||||
const addDoneList = (id, text) => { | ||||||
const done = { | ||||||
id, | ||||||
text, | ||||||
checked: false | ||||||
} | ||||||
setDones(dones => dones.concat(done)); | ||||||
} | ||||||
const onRemove = id => { | ||||||
setTodos(todos => todos.filter(todo => todo.id !==id)) | ||||||
} | ||||||
const onRemove_dn = id =>{ | ||||||
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. 함수명에 camelCase와 underscore를 혼용하셨는데 camelCase로 통일하는건 어떨까요~? |
||||||
setDones(dones => dones.filter(done => done.id !==id)) | ||||||
} | ||||||
Comment on lines
+112
to
+117
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. 코드가 중복되어 보이는데 하나의 함수로 만들면 어떨까요! |
||||||
// const [virtuals, setVirtuals] = useState([]); | ||||||
// const virtualList = (id, text, checked) =>{ | ||||||
// const virtual = { | ||||||
// id, | ||||||
// text, | ||||||
// checked | ||||||
// } | ||||||
// setVirtuals(virtuals => virtuals.concat(virtual)); | ||||||
// } | ||||||
|
||||||
const onChecked = (id) =>{ | ||||||
setTodos(todos => | ||||||
todos.map(todo => | ||||||
todo.id===id ? {...todo, checked: !todo.checked} : todo, | ||||||
) | ||||||
); | ||||||
// reArray(todos); | ||||||
|
||||||
|
||||||
|
||||||
}; | ||||||
|
||||||
const reArray = (todos) =>{ | ||||||
// const virtuals = todos; | ||||||
// setVirtuals(virtuals => virtuals.filter(virtual=> virtual.checked !==true)) | ||||||
// console.log(virtuals); | ||||||
// setTodos(todos => todos.filter(todo => todo.checked !== false)) | ||||||
// console.log(todos); | ||||||
// setTodos(todos => | ||||||
// todos.map(todo => | ||||||
// todo.checked===true ? {...todo, id: id+5} : todo, | ||||||
// ) | ||||||
// ); | ||||||
// setTodos(todos => todos.concat(virtuals)) | ||||||
// console.log(todos); | ||||||
// setVirtuals([]) | ||||||
} | ||||||
|
||||||
return ( | ||||||
<div> | ||||||
<h1>17기 프론트 화이팅~ 우하하</h1> | ||||||
</div> | ||||||
<body> | ||||||
<Container> | ||||||
<Title>T O - D O  L I S T</Title> | ||||||
<TodoInput | ||||||
addTodoList={addTodoList} | ||||||
/> | ||||||
<TodoTitle>To-Do ({todos.length})<TodoRldBtn onClick = {() => {setTodos([])}}>🔄</TodoRldBtn></TodoTitle> | ||||||
<TodoBox> | ||||||
<TodoList todos={todos} | ||||||
onRemove={onRemove} | ||||||
addDoneList={addDoneList} | ||||||
onChecked = {onChecked}/> | ||||||
</TodoBox> | ||||||
<DoneTitle>Done ({dones.length})<DoneRldBtn onClick = {() => {setDones([])}}>🔄</DoneRldBtn></DoneTitle> | ||||||
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. 버튼 누르면 한번에 초기화시키는 기능 좋네요 ㅎㅎ |
||||||
<DoneBox> | ||||||
<DoneList dones={dones} | ||||||
onRemove_dn={onRemove_dn} | ||||||
addTodoList={addTodoList}/> | ||||||
</DoneBox> | ||||||
</Container> | ||||||
</body> | ||||||
Comment on lines
+157
to
+177
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. 혹시 여기 |
||||||
); | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const TextBox = styled.div` | ||
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. 주로 |
||
width: 100%; | ||
border-color: white; | ||
color: white; | ||
font-size: 22px; | ||
font-weight: medium; | ||
height: 23px; | ||
margin: 0; | ||
` | ||
const DoneBox = styled.div` | ||
position: relative; | ||
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. position속성도 좋지만 flex-box도 많이 활용해보셨으면 좋겠어요! 정말 편리한 아이랍니다ㅎㅎ |
||
display: flex; | ||
width: 90%; | ||
margin-left: 10%; | ||
margin-top: 0.7rem; | ||
` | ||
const RtnBtn = styled.div` | ||
background-color: black; | ||
border: 1.5px solid red; | ||
border-radius: 5%; | ||
height: 23px; | ||
width: 60px; | ||
color : red; | ||
font-size: 19px; | ||
font-weight: medium; | ||
margin-right: 25px; | ||
text-align: center; | ||
` | ||
const DltBtn = styled.div` | ||
background-color: black; | ||
border: none; | ||
border-radius: 5%; | ||
height: 22px; | ||
width: 22px; | ||
color : white; | ||
font-size: 20px; | ||
font-weight: medium; | ||
margin-left : 10px; | ||
Comment on lines
+20
to
+41
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.
|
||
` | ||
|
||
const DoneItem = ({done, onRemove_dn, addTodoList})=>{ | ||
const {id, text} = done; | ||
const onReturn = (id, text) =>{ | ||
onRemove_dn(id); | ||
addTodoList(text); | ||
|
||
} | ||
|
||
return ( | ||
<DoneBox> | ||
<RtnBtn onClick={() => onReturn(id, text)}>복귀</RtnBtn> | ||
<TextBox>{text}</TextBox> | ||
<DltBtn onClick={() => onRemove_dn(id)}>X</DltBtn> | ||
</DoneBox> | ||
); | ||
|
||
} | ||
|
||
export default DoneItem; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import DoneItem from './DoneItem'; | ||
|
||
const DoneList = ({dones, onRemove_dn, addTodoList}) =>{ | ||
return ( | ||
<div> | ||
{dones.map(done =>( | ||
<DoneItem done={done} key = {done.id} onRemove_dn = {onRemove_dn} addTodoList={addTodoList}/> | ||
// 아 뭔가 이렇게 이중으로 안 넘기고 바로 지우는 방법도 있을 것 같은데... | ||
Comment on lines
+7
to
+9
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.
|
||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default DoneList; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,61 @@ | ||||||||||
import {React, useState} from 'react'; | ||||||||||
import styled from 'styled-components'; | ||||||||||
|
||||||||||
const InputBox = styled.div` | ||||||||||
margin-left: 10%; | ||||||||||
margin-top: 1rem; | ||||||||||
width:80%; | ||||||||||
height: 35px; | ||||||||||
border-style: solid; | ||||||||||
border-width: 1px; | ||||||||||
border-color: white; | ||||||||||
Comment on lines
+9
to
+11
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
|
||||||||||
position: relative; | ||||||||||
display: flex; | ||||||||||
` | ||||||||||
const TextInput = styled.input` | ||||||||||
width: 90%; | ||||||||||
height: 32px; | ||||||||||
text-align: center; | ||||||||||
background-color: black; | ||||||||||
font-size: 15px; | ||||||||||
color: gray; | ||||||||||
border-style:none; | ||||||||||
` | ||||||||||
const InputButton = styled.button` | ||||||||||
position: relative; | ||||||||||
background-color: white; | ||||||||||
border: solid 0.5px white; | ||||||||||
width: 10%; | ||||||||||
height: 35px; | ||||||||||
text-align: center; | ||||||||||
color: black; | ||||||||||
font-size: 28px; | ||||||||||
` | ||||||||||
|
||||||||||
|
||||||||||
const TodoInput = ({addTodoList}) => { | ||||||||||
const [value, setValue] = useState(""); | ||||||||||
const onChange = e => { | ||||||||||
setValue(e.target.value); | ||||||||||
} | ||||||||||
|
||||||||||
const onSubmit = (e) =>{ | ||||||||||
e.preventDefault(); | ||||||||||
addTodoList(value); | ||||||||||
setValue(""); | ||||||||||
} | ||||||||||
return( | ||||||||||
<form onSubmit={onSubmit}> | ||||||||||
<InputBox> | ||||||||||
<TextInput | ||||||||||
placeholder=" 할 일을 입력해주세요" | ||||||||||
value={value} | ||||||||||
onChange={onChange} | ||||||||||
></TextInput> | ||||||||||
<InputButton>+</InputButton> | ||||||||||
</InputBox> | ||||||||||
</form> | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
export default TodoInput; |
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.
저도 이렇게 사용했었는데
React
를 적어주지 않아도 되는 걸 이번 코드 리뷰 하면서 처음 알게 됐어요!!예린님 과제에서 문기님이 코드 리뷰 해주신 부분 참고하시면 도움 되실 것 같아요!!! 코드 리뷰