Skip to content

[10기 박은혜] TodoList with CRUD #221

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

renee13wi
Copy link

과제 PR을 늦게 올리게 되어 1주차 수업에 코드리뷰는 받지 못하게 되었으나,..
그래도 1주차부터 PR을 놓치면 안될 것 같아서 일단 올리겠습니다!
(1주차부터 놓치면 2주차는 아예 손을 놓아버릴 것 같아서..ㅠㅠ)

앗,, PR을 적고나니 제가 미처 하지 못한 부분이 있었네요!
todo list를 더블클릭했을 때 input 모드로 변경.
ㄴ 이 부분은 제가 추후에 작업하여 커밋해보도록 하겠습니다~.~


🎯 요구사항

  • todo list에 todoItem을 키보드로 입력하여 추가하기
  • todo list의 체크박스를 클릭하여 complete 상태로 변경. (li tag 에 completed class 추가, input 태그에 checked 속성 추가)
  • todo list의 x버튼을 이용해서 해당 엘리먼트를 삭제
  • todo list를 더블클릭했을 때 input 모드로 변경. (li tag 에 editing class 추가) 단 이때 수정을 완료하지 않은 상태에서 esc키를 누르면 수정되지 않은 채로 다시 view 모드로 복귀
  • todo list의 item갯수를 count한 갯수를 리스트의 하단에 보여주기
  • todo list의 상태값을 확인하여, 해야할 일과, 완료한 일을 클릭하면 해당 상태의 아이템만 보여주기

🎯🎯 심화 요구사항

  • localStorage에 데이터를 저장하여, TodoItem의 CRUD를 반영하기. 따라서 새로고침하여도 저장된 데이터를 확인할 수 있어야 함

renee13wi added 3 commits July 8, 2021 17:34
- 페이지 생성
- todo 추가
- todo count 추가
- todo all, active, completed 분기 처리 중
- Storage 세팅
- Todolist active, completed 분기 처리
- Constant 처리
- toggleTodo, removeTodo => App 이동
Copy link

@nerdyinu nerdyinu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 봤습니다! 전체적으로 함수 활용에서 미스하신 부분들은 참고하실 만한 페이지를 링크해놓았으니 보시면서 수정하시면 좋을 것 같아요!

return item.status = "active"
} else if (item.status == "active") {
return item.status = "completed"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분은 if(item.id===target.id)
item.status ==="completed"? item.status="active' : item.status="completed" 이렇게 줄여볼 수 있을 것 같습니다. 그리고 현재는 리턴식에 대입문이 쓰여서 리턴하려는 값이 명확하지 않습니다. 리턴을 생략할 수 있습니다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아,, 그렇네요!! 좋은 리뷰 감사합니다 👍

this.todos = this.todos.filter(item => {
if(item.id !== target.id) {
return item
}
Copy link

@nerdyinu nerdyinu Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter()메서드는 매개변수 안에 조건식에 해당하는 배열을 리턴하기 때문에
filter(item=> item.id!==target.id) 이렇게 쓰시면 됩니다.
https://ko.javascript.info/array-methods 여길 참고해 보세요!

this.todoList.insertAdjacentHTML('beforeend', this.todoTemplate(item))
})
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map은 배열을 반환하는 함수라 이렇게 insertAdjacentHTML처럼 쓰는 것은 정확하지 않습니다. 의도하신 부분대로라면 forEach가 맞겠네요.

set: (key, value) => {
localStorage.setItem(key, JSON.stringify(value))
}
}
Copy link

@nerdyinu nerdyinu Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getter와 setter는

get getstorage(todos_data){
}
set setstorage(key,value){
}

이런 식으로 콜론 없이 써야 한답니다. https://ko.javascript.info/property-accessors 여길 참고해보세요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요! 좋은 리뷰 감사합니다~~!

@@ -0,0 +1,3 @@
const $ = (selector) => document.querySelector(selector)

export default $

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모듈 활용 좋아요 👍

case STATUS_COMPLETED :
this.handleMapCompletedTodo()
break;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch문에는 default값을 선언해주는 것이 좋습니다. 이렇게 switch문을 활용할 수도 있지만 template 자체에 조건문을 포함하여 리턴하면 훨씬 깔끔해진답니다!

` ${filteredItems.map(({ id, content, isComplete }) => `
    <li class="${isComplete ? "completed" :'false'} ${selectedItem===id?"editing":""}" data-id="${id}">
        <div class="view">
            <input class="toggle" type="checkbox" ${isComplete? "checked" : ''}/>
            <label class="label">${content}</label>
            <button class="destroy"></button>
        </div>
        <input class="edit" value="${content}"/>
    </li>`).join(``)}``

이런 방식을 참고해보세요!

@renee13wi
Copy link
Author

잘 봤습니다! 전체적으로 함수 활용에서 미스하신 부분들은 참고하실 만한 페이지를 링크해놓았으니 보시면서 수정하시면 좋을 것 같아요!

@renee13wi renee13wi closed this Jul 13, 2021
@renee13wi renee13wi reopened this Jul 13, 2021
- completed 일 때 completed 클래스 추가
- active 일때 active 클래스 추가
todos: this.todos,
onToggleTodo: this.handleToggleTodo.bind(this),
onRemoveTodo: this.handleRemoveTodo.bind(this)
})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bind를 왜 하는지?

this.onRemoveTodo(e.target)
} else if(e.target.classList.contains("toggle")) {
this.onToggleTodo(e.target)
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains 말고 좀 더 좋은 방법은 없을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants