-
Notifications
You must be signed in to change notification settings - Fork 8
[2주차] 이효린 미션 제출합니다. #7
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?
Changes from 1 commit
f77ec81
283fb0d
2084c35
88b2c19
b8dda23
84775e7
b078703
c93b636
c50916b
af732c8
fea26ee
85abe44
031827f
a7a470c
f85502f
f65969a
d957d87
0de0688
eaf3c16
779bed8
5fd92bc
29b4b6e
b835b2d
32fe0fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,7 @@ body { | |
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from '@emotion/react'; | ||
| import { deleteFromLocalStorage } from '../utils/deleteFromLocalStorage'; | ||
| import { getLocalStorage } from '../utils/getLocalStorage'; | ||
|
|
||
| export const DeleteButton = ({ id, setTodoList }) => { | ||
| return ( | ||
| <div | ||
| css={css({ cursor: 'pointer' })} | ||
| onClick={() => { | ||
| deleteFromLocalStorage(id); | ||
| setTodoList(getLocalStorage()); | ||
| }} | ||
| > | ||
|
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. uills부분 한번 더 배우고갑니다! onClick이벤트 핸들러를 통해로컬 스토리지 적용한 부분 정말 간결하고 저도 이렇게 작성하고싶어요! |
||
| 🗑️ | ||
| </div> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from '@emotion/react'; | ||
| import { DeleteButton } from './DeleteButton'; | ||
| import { updateFromLocalStorage } from '../utils/updateFromLocalStorage'; | ||
| import { getLocalStorage } from '../utils/getLocalStorage'; | ||
| export const TodoItem = ({ todoList, setTodoList }) => | ||
| todoList.map((todo, index) => ( | ||
|
Comment on lines
+7
to
+8
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를 받고 todo에 대한 UI를 렌더링 하는 역할을 하는 것이 적절해보입니다. |
||
| <div | ||
| key={index} | ||
| css={css({ | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| height: '20px', | ||
| width: '100%', | ||
| })} | ||
| > | ||
| <div | ||
| css={css({ | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| textAlign: 'center', | ||
| alignItems: 'center', | ||
| width: '100%', | ||
| justifyContent: 'space-between', | ||
| })} | ||
| > | ||
| <div | ||
| css={css({ | ||
| cursor: 'pointer', | ||
| textDecoration: todo.done ? 'line-through' : 'none', | ||
|
Comment on lines
+29
to
+32
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. 할 일 항목 완료여부에 따라 동적으로 설정하신 부분도 명확하게 보여서 너무 좋아요!!!!! |
||
| color: todo.done ? '#D3D3D3' : '#000', | ||
| textAlign: 'center', | ||
| })} | ||
| onClick={() => { | ||
| updateFromLocalStorage(todo.id); | ||
| setTodoList(getLocalStorage()); | ||
|
Comment on lines
+37
to
+38
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.todo} | ||
| </div> | ||
| <DeleteButton id={todo.id} setTodoList={setTodoList} /> | ||
| </div> | ||
| </div> | ||
| )); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,13 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from '@emotion/react'; | ||
| import { updateFromLocalStorage } from '../utils/updateFromLocalStorage'; | ||
| import { getLocalStorage } from '../utils/getLocalStorage'; | ||
| import { deleteFromLocalStorage } from '../utils/deleteFromLocalStorage'; | ||
| import { TodoItem } from './TodoItem'; | ||
|
|
||
| function TodoList({ notDoneTodoList, setTodoList }) { | ||
| const doneTodo = (id) => { | ||
| updateFromLocalStorage(id); | ||
| setTodoList(getLocalStorage()); | ||
| }; | ||
| return ( | ||
| <div | ||
| css={css({ | ||
| height: '235px', | ||
| width: '324px', | ||
| height: '220px', | ||
| width: '100%', | ||
| borderBottom: 'solid 1px lightgray', | ||
| padding: '18px 18px 0 18px', | ||
| })} | ||
|
|
@@ -29,48 +23,10 @@ function TodoList({ notDoneTodoList, setTodoList }) { | |
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: '10px', | ||
| paddingRight: '20px', | ||
| })} | ||
| > | ||
| {notDoneTodoList.map((todo, index) => ( | ||
| <div | ||
| key={index} | ||
| css={css({ | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| height: '20px', | ||
| width: '80%', | ||
| })} | ||
| > | ||
| <div | ||
| css={css({ | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| textAlign: 'center', | ||
| alignItems: 'center', | ||
| width: '100%', | ||
| })} | ||
| > | ||
| * | ||
| <div | ||
| onClick={() => { | ||
| updateFromLocalStorage(todo.id); | ||
| setTodoList(getLocalStorage()); | ||
| }} | ||
| > | ||
| {todo.todo} | ||
| </div> | ||
| <div | ||
| onClick={() => { | ||
| deleteFromLocalStorage(todo.id); | ||
| setTodoList(getLocalStorage()); | ||
| }} | ||
| > | ||
| ❌ | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| <TodoItem todoList={notDoneTodoList} setTodoList={setTodoList} /> | ||
|
||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
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.
LocalStorage를 왜 사용하는지 생각해보셨으면 좋겠습니다. LocalStorage를 데이터 원본 저장소처럼 활용하고 있는데요. 성능 면이나 관리 면에서 그냥 메모리에 있는 상태를 원본으로 두고 LocalStorage는 백업 용도로 사용하는 것이 좋겠습니다.
저라면 Todo State를 변경하고 그에 대한 Effect로 LocalStorage에 상태를 저장할 것 같네요.
그렇게 되면 여기서는 위에서 말한 deleteTodo 함수만 호출하면 됩니다.