Skip to content

Commit

Permalink
feat: 결과 선택 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
zwonkim committed Aug 12, 2024
1 parent e9013a7 commit 47eac3a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/pages/choice-color/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ function ChoiceColor() {
const [selectedColor, setSelectedColor] = useState('');
const [stageNum, setStageNum] = useState(0);

// const stageNum = selectedTypes.length;
const selectedTypesLength = selectedTypes.length;
const MAX_STAGE_NUM = choiceColorData.length;

const basicColorOptions = useMemo(
() => shuffle(choiceColorData[stageNum]),
[stageNum]
);
const basicColorOptions = useMemo(() => {
if (stageNum < MAX_STAGE_NUM) {
return shuffle(choiceColorData[stageNum]);
}
return choiceColorData[stageNum];
}, [stageNum]);

const bonusColorTypes = useSelectBonusColorTypes(
selectedTypes,
Expand All @@ -29,6 +31,8 @@ function ChoiceColor() {
const userImg = useCropImg();

const onBasicClick = (selectedChip: ChoiceColorDataType) => {
if (!(stageNum < MAX_STAGE_NUM)) return;

setSelectedTypes((prev) => [...prev, selectedChip.type]);
setSelectedColor(selectedChip.color);
};
Expand All @@ -42,11 +46,11 @@ function ChoiceColor() {

return () => clearTimeout(timeout);
}
}, [selectedColor]);
}, [stageNum, selectedColor]);

return (
<S.Wrapper>
{stageNum < MAX_STAGE_NUM ? (
{selectedTypesLength < MAX_STAGE_NUM ? (
<BasicStage
userImg={userImg}
stageNum={stageNum}
Expand Down

0 comments on commit 47eac3a

Please sign in to comment.