@@ -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 >
0 commit comments