Fix poll showing NaN when total votes = 0

So 0/0 = NaN
This commit is contained in:
Lim Chee Aun 2022-12-25 23:29:25 +08:00
parent 318c2aeffc
commit 3daa7e4f9d

View file

@ -982,10 +982,11 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
{voted || expired ? ( {voted || expired ? (
options.map((option, i) => { options.map((option, i) => {
const { title, votesCount: optionVotesCount } = option; const { title, votesCount: optionVotesCount } = option;
const percentage = const percentage = pollVotesCount
((optionVotesCount / pollVotesCount) * 100).toFixed( ? ((optionVotesCount / pollVotesCount) * 100).toFixed(
roundPrecision, roundPrecision,
) || 0; )
: 0;
// check if current poll choice is the leading one // check if current poll choice is the leading one
const isLeading = const isLeading =
optionVotesCount > 0 && optionVotesCount > 0 &&