Skip to content
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주차] 전시원 미션 제출합니다. #23

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c6feae2
[⌚️feat] : Init project
Mar 24, 2022
f5b938e
[⌚️feat] : Add list
Mar 24, 2022
4427d83
[⌚️feat] : Save data
Mar 24, 2022
4b54ec9
[⌚️feat] : Add toggle
Mar 24, 2022
e8bbcba
[⌨️chore] : Modify rendering style
Mar 24, 2022
6b36e58
[⌚️feat] : Add delete button
Mar 24, 2022
28017c7
[⌚️feat] : Add count number of list
Mar 24, 2022
bb2753b
[📱fix] : Fix localStorage save updating
Mar 24, 2022
e9d358b
[🧨refactor] : Devide code into component
Mar 24, 2022
743fdc4
[🧨refactor] : Devide code into component
Mar 24, 2022
352336c
[🧨refactor] : Devide code into component
Mar 24, 2022
cd6291c
[🧨refactor] : Devide code into component
Mar 24, 2022
11967de
[📱fix] : Find bug
Mar 24, 2022
5274f66
[⌨️chore] : Set maxLength
Mar 24, 2022
544079f
[📱fix] : Find bug
Mar 24, 2022
b2cebe8
[📱fix] Fix bug
Mar 24, 2022
ac130c1
[🧨refactor] : Add css style in all component
Mar 24, 2022
8438aa6
Test commit
Mar 24, 2022
ac54062
[💻build] : typescript
Mar 31, 2022
e8a6881
[🧨refactor] : Apply type and refactor function
Apr 1, 2022
0ad9ee6
[🧨refactor] : Check Type
Apr 1, 2022
ddcb16c
[🧨refactor] : Check type
Apr 1, 2022
c3ef0e8
[🧨refactor] : Apply typescript all components
Apr 1, 2022
fe2b790
[⌨️chore] : delete ""
Apr 1, 2022
9b333ab
[⌨️chore] : delete inline style
Apr 1, 2022
85b97cd
[⌨️chore] : delete inline style
Apr 1, 2022
7554c72
[🧨refactor] : add globalStyle
Apr 1, 2022
f0f19a2
[⌨️chore] : edit
Apr 1, 2022
96519d5
[⌚️feat] : Add custom hooks
Apr 1, 2022
1976c20
[⌚️feat] : Prevent duplicated input data
Apr 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/components/AllContents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import InputForm from '../InputForm';
import YetList from '../YetList';
import DoneList from '../DoneList';
import { ITodoList } from 'interface';
import getLocalValue from "../../hooks/getLocalValue";
import getLocalValue from '../../hooks/getLocalValue';

const Index = () => {
const listText = 'list';

const localData = getLocalValue()
const localData = getLocalValue();
Copy link

Choose a reason for hiding this comment

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

앗, 이 부분 코멘트 남겨주셔서 감사했습니다!

// localDate 를 처음에 가져와서 새로고침해도 데이터가 유지되게 설정

const [yetNum, setYetNum] = useState(0);
Expand All @@ -20,21 +20,26 @@ const Index = () => {
setContents(e.target.value);
const handleFormSubmit = (e: React.SyntheticEvent) => {
e.preventDefault();

const obj = {
contents,
id: Date.now(),
isDone: false,
};
setList((prev: []) => [...prev, obj]);
setContents('');
const val = getLocalValue();
const checkArry = val.filter((item: ITodoList) => {
return item.contents === contents;
});
if (checkArry.length === 0) {
const obj = {
contents,
id: Date.now(),
isDone: false,
};
setList((prev: []) => [...prev, obj]);
Copy link

Choose a reason for hiding this comment

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

타입을 string[] 이나 Array으로 해주면 명확해질 것 같아요!!

setContents('');
}
};
const onToggle = (e: React.MouseEvent<HTMLButtonElement>) => {
// 클릭된 값

const text = (e.target as HTMLElement).textContent;
Copy link

Choose a reason for hiding this comment

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

TS에 as라는 문법이 있는지 처음 알게되었습니다. 감사합니다!

Copy link
Author

Choose a reason for hiding this comment

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

저도 구글에서 찾아보다 그냥 가져와서 알게됐어요 ㅎㅎ;

Copy link

Choose a reason for hiding this comment

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

HTML 구조에 의존적인 로직보다는, 클릭한 요소의 id를 필터링해서 토글시키는 방법이 좋을 것 같습니다.

// 로컬스토리지에 저장된 값
const data = getLocalValue()
const data = getLocalValue();
// 두 값을 이용해서 클릭된 값만 isDone 상태 토글
let indexClicked = 0;
let obj;
Expand All @@ -59,7 +64,7 @@ const Index = () => {

// 현재 데이터 가져오기

const data = getLocalValue()
const data = getLocalValue();
// 데이터 삭제
const updatedDate = data.filter((item: ITodoList) => {
return item.contents.trim() !== text.trim();
Copy link

Choose a reason for hiding this comment

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

trim이라는 함수를 찾아보니까 문자열 양끝 공백을 사라지게 하는 함수군요 ! 디테일 배워갑니당

Expand All @@ -81,8 +86,7 @@ const Index = () => {
}, [list]);

const findNum = () => {

const data = getLocalValue()
const data = getLocalValue();
let yetCtn = 0;
let doneCtn = 0;

Expand Down