-
Notifications
You must be signed in to change notification settings - Fork 7
[4주차] 강태이/todolist Edit, localStorage 기능 구현 #60
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
base: 강태이/main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uAC15\uD0DC\uC774/4\uC8FC\uCC28"
Conversation
yezzan9
left a comment
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.
수고하셨습니다 태이님!
현재 코드를 보니 prettier가 제대로 설정이 안 되어있는 것 같아요💦
확인 후 설정부탁드립니다 !!
| const TodoList = ({ todos, setTodos, activeCategory }) => { | ||
| const [editTexts, setEditTexts] = useState({}); | ||
|
|
||
| const handleDelete = (id) => { | ||
| setTodos(todos.filter(todo => todo.id !== id)); | ||
| }; | ||
|
|
||
| const handleToggleComplete = (id) => { | ||
| setTodos( | ||
| todos.map(todo => | ||
| todo.id === id ? { ...todo, completed: !todo.completed } : todo | ||
| ) | ||
| ); | ||
| }; |
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.
이 부분 들여쓰기가 4칸으로 되어있는 것 같아요 ! 2칸으로 수정해주세용👀
| <TodoListContainer> | ||
| <StyledText>{todos.filter(todo => !todo.completed).length} tasks remaining</StyledText> | ||
| <div className="task-list"> | ||
| {filteredTodos.map(todo => ( | ||
| <TaskItem key={todo.id}> | ||
| {todo.isEditing ? ( | ||
| <> | ||
| <TaskTop style={{ flexDirection: "column", alignItems:"flex-start"}}> | ||
| <div style={{marginBottom: "8px", fontWeight:"bold"}}> | ||
| New name for <span style={{color: "#555"}}>{todo.text}</span> | ||
| </div> | ||
|
|
||
| <input | ||
| type="text" | ||
| value={editTexts[todo.id] || ''} | ||
| onChange={(e) => handleEditChange(todo.id, e.target.value)} | ||
| style={{ width: "400px", padding: "8px", fontSize: "16px" }} | ||
| /> | ||
| </TaskTop> | ||
|
|
||
| <TaskActions> | ||
| <CancelButton onClick={() => handleCancel(todo.id)}>Cancel</CancelButton> | ||
| <SaveButton onClick={() => handleSave(todo.id)}>Save</SaveButton> | ||
| </TaskActions> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <TaskTop> | ||
| <StyledCheckbox | ||
| checked={todo.completed} | ||
| onChange={() => handleToggleComplete(todo.id)} | ||
| /> | ||
| <span style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}> | ||
| {todo.text} | ||
| </span> | ||
| </TaskTop> | ||
| <TaskActions> | ||
| <EditButton onClick={() => handleEdit(todo.id, todo.text)}>Edit</EditButton> | ||
| <DeleteButton onClick={() => handleDelete(todo.id)}>Delete</DeleteButton> | ||
| </TaskActions> | ||
| </> | ||
| )} | ||
| </TaskItem> |
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.
이 부분도요!🥺
| <input | ||
| type="text" | ||
| value={editTexts[todo.id] || ''} | ||
| onChange={(e) => handleEditChange(todo.id, e.target.value)} | ||
| style={{ width: "400px", padding: "8px", fontSize: "16px" }} | ||
| /> |
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.
기존에 구현했던 Input 컴포넌트를 재사용하도록 수정하면 더 좋을 것 같아요!
1. 무엇을??
기존 Todo List 구현하기 과제에서 Edit, Cancel, Save 기능을 구현하였습니다.
tasks 상태를 localStorage에 저장하여 브라우저를 닫았다가 다시 열어도 데이터가 유지되도록 하였습니다.
2. 어떤 작업을 하였나요??
todolist 컴포넌트에서 isEditing 상태를 추가하고 Edit 버튼 클릭시 cancel/save버튼 렌더링,
cancel 버튼 누르면 취소, save버튼 누르면 수정된 이름으로 반영
tasks 상태를 localStorage에 저장
3. 스크린샷