Skip to content

Commit

Permalink
chore(keywordSubscribe): 피드백 반영
Browse files Browse the repository at this point in the history
- 키워드 구독 전송을 keydown -> form 제출 형식으로 변경
  • Loading branch information
pp449 committed Feb 6, 2024
1 parent d36a5aa commit 4013345
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pages/KeywordSubscribe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useInput from '@hooks/useInput';
import useToasts from '@hooks/useToast';
import RegisteredKeywordList from '@pages/KeywordSubscribe/components/RegisteredKeywordList';
import { THEME } from '@styles/ThemeProvider/theme';
import { KeyboardEventHandler, useEffect, useState } from 'react';
import { FormEvent, FormEventHandler, useEffect, useState } from 'react';

const KeywordSubscribe = () => {
const [keywords, setKeywords] = useState<string[]>([]);
Expand All @@ -34,8 +34,9 @@ const KeywordSubscribe = () => {
setKeywords((prevKeyword) => prevKeyword.filter((key) => key !== keyword));
};

const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (e) => {
if (e.key !== 'Enter' || e.nativeEvent.isComposing) return;
const handleSubmit: FormEventHandler<HTMLFormElement> = (
e: FormEvent<HTMLFormElement>,
) => {
e.preventDefault();
onClickSubmit();
};
Expand Down Expand Up @@ -73,7 +74,7 @@ const KeywordSubscribe = () => {
fetchKeywords();
}, []);

const checkIsAvailable = () => (inputKeyword.length > 1 ? true : false);
const checkIsAvailable = () => inputKeyword.length > 1;

return (
<>
Expand All @@ -82,18 +83,16 @@ const KeywordSubscribe = () => {
<InformUpperLayout.InformSubTitle subTitle={KEYWORD_PAGE.SUB_TITLE} />
</InformUpperLayout>

<InputWrapper>
<InputWrapper onSubmit={handleSubmit}>
<KeywordInput
onChange={setInputKeyword}
placeholder={KEYWORD_PAGE.PLACEHOLDER}
maxLength={15}
onKeyDown={handleKeyDown}
value={inputKeyword}
/>
<KeywordSubmit
disabled={!checkIsAvailable()}
isAvailable={checkIsAvailable()}
onClick={onClickSubmit}
>
등록
</KeywordSubmit>
Expand All @@ -109,7 +108,7 @@ const KeywordSubscribe = () => {

export default KeywordSubscribe;

const InputWrapper = styled.div`
const InputWrapper = styled.form`
padding: 0 20px 0 20px;
position: relative;
`;
Expand Down

0 comments on commit 4013345

Please sign in to comment.