-
Notifications
You must be signed in to change notification settings - Fork 4
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
[feat/CK-142] 로드맵 생성페이지 버그를 해결한다 #101
Changes from 8 commits
08de279
7c2de5e
9d1b043
cc428bc
fad9023
2f1a0a6
846421f
1a50d07
3cc87f7
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 |
---|---|---|
|
@@ -9,7 +9,8 @@ type TagProps = { | |
getTags: (tags: string[]) => void; | ||
}; | ||
const Tag = ({ getTags }: TagProps) => { | ||
const { tags, ref, getAddedTagText, checkIsTagCountMax } = useCreateTag(); | ||
const { tags, ref, addTagByButton, addTagByEnter, checkIsTagCountMax, delegeTag } = | ||
useCreateTag(); | ||
|
||
useEffect(() => { | ||
getTags(tags); | ||
|
@@ -21,10 +22,15 @@ const Tag = ({ getTags }: TagProps) => { | |
<InputDescription text='컨텐츠와 어울리는 태그를 작성해주세요' /> | ||
<S.TagWrapper> | ||
{tags.map((item) => ( | ||
<S.AddedTagItem key={item}>{item}</S.AddedTagItem> | ||
<> | ||
<S.AddedTagItem key={item}># {item}</S.AddedTagItem> | ||
<S.DeleteButton value={item} onClick={delegeTag}> | ||
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.
|
||
X | ||
</S.DeleteButton> | ||
</> | ||
))} | ||
<TagItem ref={ref} /> | ||
{checkIsTagCountMax() && <S.AddButton onClick={getAddedTagText}>+</S.AddButton>} | ||
<TagItem ref={ref} addTagByEnter={addTagByEnter} placeholder='# 태그명' /> | ||
{checkIsTagCountMax() && <S.AddButton onClick={addTagByButton}>+</S.AddButton>} | ||
</S.TagWrapper> | ||
</S.Container> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ export const useCreateTag = () => { | |
const [tags, setTags] = useState<string[]>([]); | ||
const ref = useRef<HTMLInputElement | null>(null); | ||
|
||
const getAddedTagText = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.preventDefault(); | ||
const getAddedTagText = () => { | ||
if (ref.current === null) return; | ||
if (ref.current.value === '') return; | ||
|
||
|
@@ -16,9 +15,30 @@ export const useCreateTag = () => { | |
ref.current.value = ''; | ||
}; | ||
|
||
const addTagByButton = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.preventDefault(); | ||
getAddedTagText(); | ||
}; | ||
|
||
const addTagByEnter = (e: React.KeyboardEvent) => { | ||
if (e.code === 'Enter') { | ||
e.preventDefault(); | ||
getAddedTagText(); | ||
} | ||
}; | ||
|
||
const checkIsTagCountMax = () => { | ||
return tags.length < TAG_LIMIT; | ||
}; | ||
|
||
return { tags, ref, getAddedTagText, checkIsTagCountMax }; | ||
const delegeTag = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
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. delete 를 뜻하는게 맞을까여?? 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. 헉 매의눈 ㅇㅈ... 주의하겠슴미다😭 |
||
e.preventDefault(); | ||
|
||
const target = e.target as HTMLButtonElement; | ||
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. e.currentTarget은 항상 button 요소가 되겠지만, e.target은 다른 요소가 될 수도 있어서 target에 타입 단언을 해주어야 하는군요👍 |
||
|
||
setTags((prev) => { | ||
return prev.filter((tag) => tag !== target.value); | ||
}); | ||
Comment on lines
+39
to
+41
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. 문득 생각이 든건데, 이미 추가한 태그를 똑같은 이름으로 추가하면 어떻게 되는건가요?
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. 완전 예리하네요..!! 태그 생성은 중복 가능해도 좋을 것 같은데, 삭제 자체는 한개만 되어야 하는게 맞는 것 같아요!! |
||
}; | ||
return { tags, ref, addTagByButton, addTagByEnter, checkIsTagCountMax, delegeTag }; | ||
}; |
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.
on Change event 를 분리하지 않고 콜백으로 넣은 이유가 있을까용??
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.
이 핸들러 함수에 e 말고도 다른 인자도 들어가야해서 콜백으로 넣어줬어요! 근데 이게 문제가... 태그를 input으로 명시하면 e의 타입이 추론이 되는데 스타일드 컴포넌트로 명시하니깐 타입 추론이 안되더라고라... ㄹㅇ 환장할 노릇;; 그래서 일단 타입을 명시해줬는데 왜 이러는지 혹시 아실까용 ㅜ