Skip to content

Commit

Permalink
fix : 키워드 선택 오류 수정 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangminguu authored Oct 31, 2024
1 parent 776775c commit e2f999b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/features/diary-write/emotion/ui/EmotionButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ export const EmotionButtonGroup: React.FC<EmotionButtonGroupProps> = ({
const [keywords, setKeywords] =
useState<(Emotions | null)[]>(initialKeywords);
const [activeButton, setActiveButton] = useState(0);
const [lastClicked, setLastClicked] = useState<
'keyword' | 'emotion' | null
>(null);

const handleClickKeyword = (index: number) => {
setLastClicked('keyword');

setActiveButton(index);

setKeywords((prevKeywords) => {
const newKeywords = [...prevKeywords];
newKeywords[index] = null;
Expand All @@ -32,6 +38,8 @@ export const EmotionButtonGroup: React.FC<EmotionButtonGroupProps> = ({
};

const handleClickEmotion = (selectedEmotions: Emotions[]) => {
setLastClicked('emotion');

const newEmotion = selectedEmotions[0];

if (keywords[activeButton] !== newEmotion) {
Expand All @@ -44,7 +52,8 @@ export const EmotionButtonGroup: React.FC<EmotionButtonGroupProps> = ({
return newKeywords;
});

setActiveButton(activeButton !== 4 ? activeButton + 1 : 0);
if (lastClicked !== 'keyword')
setActiveButton(activeButton !== 4 ? activeButton + 1 : 0);
}
};

Expand Down

0 comments on commit e2f999b

Please sign in to comment.