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 ? (
options.map((option, i) => {
const { title, votesCount: optionVotesCount } = option;
const percentage =
((optionVotesCount / pollVotesCount) * 100).toFixed(
const percentage = pollVotesCount
? ((optionVotesCount / pollVotesCount) * 100).toFixed(
roundPrecision,
) || 0;
)
: 0;
// check if current poll choice is the leading one
const isLeading =
optionVotesCount > 0 &&