-
Notifications
You must be signed in to change notification settings - Fork 13
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
[3주차] 정대헌 미션 제출합니다. #21
Open
jdaeheon
wants to merge
13
commits into
CEOS-Developers:master
Choose a base branch
from
jdaeheon:master
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 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
84b702d
ADD: 기본적인 틀 리팩토링, 스타일 속성 부여, JSX 요소 선언
97c1885
ADD: 아이템 리스트의 CSS 고정 높이 및 너비, 스크롤 가능 속성 추가
e34cea1
MOD: class attribute을 className으로 수정
8873d43
ADD: reducer를 이용한 input 입력 및 todo/done 리스트 구현
4750dae
MOD: CSS 스크롤바 수정, todo 클래스 명 수정, formField 문제 수정
e99b667
ADD: todo, done 아이템 카운팅, localStorage 엑세스 추가, scrollbar CSS 수정
0775348
MOD: 스타일 수정
4148872
MOD: styled components 사용(InputContainer에 시범 적용)
d379344
MOD: 주석 추가 및 일부 코드 수정
6c4147b
MOD: Context API 로직 구현
b967efe
MOD: styled component로 이사
3e1d890
MOD: 타입스크립트로 이사
621b438
FIX: quickfix on storage bug
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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const AppReducer = (state, action) => { | ||
//DELETE = 아이템 삭제, ADD = 아이템 추가, MODIFY = 아이템 type 수정(done/todo) | ||
switch (action.type) { | ||
case "DELETE": | ||
return [...state.filter((item) => item.id !== action.payload.id)]; | ||
case "ADD": | ||
return [...state.concat([action.payload])]; | ||
case "MODIFY": | ||
return [ | ||
...state.map((item) => | ||
item.id === action.payload.id | ||
? { ...item, type: item.type === "todo" ? "done" : "todo" } | ||
: item | ||
), | ||
]; | ||
default: | ||
return [...state]; | ||
} | ||
}; | ||
|
||
export default AppReducer; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { createContext, useReducer, useEffect } from "react"; | ||
import AppReducer from "./AppReducer"; | ||
|
||
const initialItems = localStorage.getItem("list") | ||
? JSON.parse(localStorage.getItem("list")) | ||
: []; | ||
|
||
export const GlobalContext = createContext(initialItems); | ||
|
||
export const GlobalProvider = ({ children }) => { | ||
const [listItems, dispatch] = useReducer(AppReducer, initialItems); | ||
|
||
useEffect(() => { | ||
localStorage.setItem("list", JSON.stringify(listItems)); | ||
}, [listItems]); | ||
|
||
// Actions | ||
const addItem = (uid, itemType, itemContent) => { | ||
dispatch({ | ||
type: "ADD", | ||
payload: { id: uid, type: itemType, content: itemContent }, | ||
}); | ||
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. uid는 유니크한 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. �아 그냥 변수 이름만 uid이고 사실 유니크 하진 않습니다, uuid를 사용해야하는 걸로 알고 있어요! |
||
}; | ||
|
||
const moveItem = (uid) => { | ||
dispatch({ | ||
type: "MODIFY", | ||
payload: { | ||
id: uid, | ||
}, | ||
}); | ||
}; | ||
|
||
const deleteItem = (uid) => { | ||
dispatch({ | ||
type: "DELETE", | ||
payload: { | ||
id: uid, | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<GlobalContext.Provider | ||
value={{ | ||
listItems: listItems, | ||
addItem, | ||
moveItem, | ||
deleteItem, | ||
}} | ||
> | ||
{children} | ||
</GlobalContext.Provider> | ||
); | ||
}; |
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.
리듀서를 사용하니까 로직이 깔끔해지는 것 같습니다 ! 저도 적용해봐야겠군뇨
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.
리듀서 너무 좋습니다 👍