Skip to content

Commit

Permalink
๐Ÿš€ Deploy #65
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaem03 authored Nov 14, 2024
2 parents 7442d17 + b7d5b64 commit 4ebb2f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/pages/nuguPatch/NuguPatch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ export const NuguPatch = () => {
try {
const userData = await getNugu();
setUpdateData(userData);
const initialSelectedChips = [
userData.keyword1,
userData.keyword2,
userData.keyword3,
];
handleClickStatus(initialSelectedChips);
} catch (err) {
console.error("Patch-user์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ ์‹คํŒจ", err);
}
Expand Down
29 changes: 22 additions & 7 deletions src/pages/nuguPatch/_hooks/usePatchChip.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import { useRecoilState } from "recoil";
import { signUpState } from "@atoms/signUpState";
import { CHIP_DATA } from "@constants/chip";
export const usePatchChip = () => {
const [updateData, setUpdateData] = useRecoilState(signUpState);
const [selectedChip, setSelectedChip] = useState(
CHIP_DATA.map(
(chip) =>
updateData.keyword1 === chip ||
updateData.keyword2 === chip ||
updateData.keyword3 === chip
)
new Array(CHIP_DATA.length).fill(false)
);
const selectedCount = selectedChip.filter((chip) => chip).length;

useEffect(() => {
const initialSelectedChips = [
updateData.keyword1,
updateData.keyword2,
updateData.keyword3,
];

const updatedChip = [...selectedChip];

initialSelectedChips.forEach((keyword) => {
const index = CHIP_DATA.indexOf(keyword);
if (index !== -1) {
updatedChip[index] = true;
}
});

setSelectedChip(updatedChip);
}, [updateData]);

const handleClickStatus = (index) => {
const updatedChip = [...selectedChip];
console.log(updatedChip);
updatedChip[index] = !updatedChip[index];

if (updatedChip.filter((chip) => chip).length > 3) {
return;
}
Expand Down

0 comments on commit 4ebb2f2

Please sign in to comment.