Skip to content

Commit aba2121

Browse files
authored
Merge pull request #247 from THIP-TextHip/hotfix/vote
fix: 기둝μž₯ νˆ¬ν‘œ 정보 νΌμ„ΌνŠΈκ°€ μ•„λ‹Œ λ“ν‘œμˆ˜λ‘œ ν‘œμ‹œλ˜λ„λ‘ μˆ˜μ •
2 parents 201c98e + b715160 commit aba2121

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

β€Žsrc/components/memory/RecordItem/PollRecord.tsxβ€Ž

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ const PollRecord = ({ content, pollOptions, postId, shouldBlur = false, onVoteUp
9191
return {
9292
...opt,
9393
percentage: updatedItem.percentage,
94+
count: updatedItem.count,
9495
isVoted: updatedItem.isVoted,
95-
isHighest: updatedItem.percentage === Math.max(...response.data.voteItems.map(item => item.percentage))
96+
isHighest: updatedItem.count === Math.max(...response.data.voteItems.map(item => item.count))
9697
};
9798
}
9899
return opt;
@@ -142,8 +143,17 @@ const PollRecord = ({ content, pollOptions, postId, shouldBlur = false, onVoteUp
142143
}
143144
};
144145

145-
// 아무도 νˆ¬ν‘œν•˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인 (λͺ¨λ“  μ˜΅μ…˜μ΄ 0%인지 확인)
146-
const hasVotes = currentOptions.some(option => option.percentage > 0);
146+
// 아무도 νˆ¬ν‘œν•˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인 (λͺ¨λ“  μ˜΅μ…˜μ΄ 0ν‘œμΈμ§€ 확인)
147+
const hasVotes = currentOptions.some(option => option.count > 0);
148+
149+
// 전체 νˆ¬ν‘œμˆ˜ 계산
150+
const totalVotes = currentOptions.reduce((sum, option) => sum + option.count, 0);
151+
152+
// 각 μ˜΅μ…˜μ˜ νΌμ„ΌνŠΈ 계산 (μ• λ‹ˆλ©”μ΄μ…˜μš©)
153+
const getPercentage = (count: number) => {
154+
if (totalVotes === 0) return 0;
155+
return (count / totalVotes) * 100;
156+
};
147157

148158
return (
149159
<PollSection ref={pollRef}>
@@ -162,7 +172,7 @@ const PollRecord = ({ content, pollOptions, postId, shouldBlur = false, onVoteUp
162172
>
163173
<PollBar>
164174
<PollBarFill
165-
percentage={hasVotes ? option.percentage : 0}
175+
percentage={hasVotes ? getPercentage(option.count) : 0}
166176
isHighest={hasVotes && option.isHighest}
167177
animate={hasVotes && animate}
168178
delay={index * 200} // 각 μ˜΅μ…˜λ§ˆλ‹€ 200ms μ§€μ—°
@@ -177,7 +187,7 @@ const PollRecord = ({ content, pollOptions, postId, shouldBlur = false, onVoteUp
177187
</PollText>
178188
{hasVotes && (
179189
<PollPercentage isHighest={hasVotes && option.isHighest}>
180-
{option.percentage}%
190+
{option.count}ν‘œ
181191
</PollPercentage>
182192
)}
183193
</PollContent>

β€Žsrc/pages/memory/Memory.tsxβ€Ž

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ const convertPostToRecord = (post: Post): Record => {
3131
isWriter: post.isWriter,
3232
isLiked: post.isLiked,
3333
isLocked: post.isLocked, // λΈ”λŸ¬ 처리 μ—¬λΆ€ μΆ”κ°€
34-
pollOptions: post.voteItems.map((item, index) => ({
35-
id: item.voteItemId.toString(),
36-
text: item.itemName,
37-
percentage: item.percentage,
38-
isHighest: index === 0,
39-
voteItemId: item.voteItemId,
40-
isVoted: item.isVoted,
41-
})),
34+
pollOptions: post.voteItems.map((item) => {
35+
const maxCount = Math.max(...post.voteItems.map(v => v.count || 0));
36+
return {
37+
id: item.voteItemId.toString(),
38+
text: item.itemName,
39+
percentage: item.percentage,
40+
count: item.count || 0,
41+
isHighest: (item.count || 0) === maxCount && maxCount > 0,
42+
voteItemId: item.voteItemId,
43+
isVoted: item.isVoted,
44+
};
45+
}),
4246
};
4347
};
4448

β€Žsrc/types/memory.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface VoteItem {
33
voteItemId: number;
44
itemName: string;
55
percentage: number;
6+
count: number;
67
isVoted: boolean;
78
}
89

@@ -82,6 +83,7 @@ export interface PollOption {
8283
id: string;
8384
text: string;
8485
percentage: number;
86+
count: number;
8587
isHighest: boolean;
8688
voteItemId: number; // νˆ¬ν‘œ API에 ν•„μš”ν•œ ID
8789
isVoted: boolean; // ν˜„μž¬ μ‚¬μš©μžκ°€ νˆ¬ν‘œν–ˆλŠ”μ§€ μ—¬λΆ€

β€Žsrc/types/record.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface VoteItemResult {
3535
voteItemId: number; // νˆ¬ν‘œ μ•„μ΄ν…œ ID
3636
itemName: string; // νˆ¬ν‘œ μ˜΅μ…˜ 이름
3737
percentage: number; // λ“ν‘œμœ¨
38+
count: number; // λ“ν‘œμˆ˜
3839
isVoted: boolean; // ν˜„μž¬ μ‚¬μš©μžκ°€ νˆ¬ν‘œν–ˆλŠ”μ§€ μ—¬λΆ€
3940
}
4041

0 commit comments

Comments
Β (0)