Skip to content

Commit b8ae48d

Browse files
Merge pull request #60 from CodeitPart2/SCRUM-81-박찬영
이모티콘 수정
2 parents 47a1ebc + e71ba18 commit b8ae48d

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

src/components/common/Emoji/Emoji.jsx

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,46 @@ function Emoji({ topReactions = [], setRecipientData }) {
3838

3939
// 이모티콘 추가 및 상태 업데이트
4040
const handleEmojiSelect = async (emojiObject) => {
41-
const { emoji } = emojiObject;
42-
const type = "increase";
43-
44-
try {
45-
await recipientsService.postRecipientsReactions(id, { emoji, type });
46-
await fetchUpdatedReactions();
47-
} catch (error) {
48-
console.error("Error sending reaction:", error);
49-
}
50-
};
41+
const { emoji } = emojiObject;
42+
const type = "increase";
43+
44+
try {
45+
// 서버에 반응을 보냄
46+
await recipientsService.postRecipientsReactions(id, { emoji, type });
47+
48+
// 반응 데이터 갱신
49+
await fetchUpdatedReactions();
50+
} catch (error) {
51+
console.error("Error sending reaction:", error);
52+
}
53+
};
54+
55+
const fetchUpdatedReactions = async () => {
56+
try {
57+
const response = await recipientsService.getRecipientsReactions(id);
58+
const updatedReactions = response.data.results;
5159

5260

53-
const fetchUpdatedReactions = async () => {
54-
try {
55-
const response = await recipientsService.getRecipientsReactions(id);
56-
const updatedReactions = response.data.results;
57-
58-
setRecipientData((prev) => ({
59-
...prev,
60-
topReactions: updatedReactions,
61-
}));
62-
63-
// 전체 이모티콘 리스트 업데이트 후 로컬 스토리지 저장
64-
setAllReactions(updatedReactions);
65-
localStorage.setItem("allReactions", JSON.stringify(updatedReactions));
66-
} catch (error) {
67-
console.error("Error fetching reactions:", error);
68-
}
69-
};
61+
const topEmojis = updatedReactions.slice(0, TOP_EMOJIS);
62+
63+
64+
const allEmojis = updatedReactions.length > 8 ? updatedReactions.slice(0, 8) : updatedReactions;
65+
66+
67+
setRecipientData((prev) => ({
68+
...prev,
69+
topReactions: topEmojis,
70+
}));
71+
72+
setAllReactions(allEmojis);
73+
74+
75+
localStorage.setItem("allReactions", JSON.stringify(allEmojis));
76+
77+
} catch (error) {
78+
console.error("Error fetching reactions:", error);
79+
}
80+
};
7081

7182
return (
7283
<ServiceContainer>

0 commit comments

Comments
 (0)