For some reason the View Count increments by 2 instead of 1. Any suggestions?
import wixData from ‘wix-data’;
//Voting and Viewing code
export function ifNull(a){
return (a===undefined) ? 0 : a;
}
var currentItem, ds;
export function ratingsDataset_ready() {
ds = $w (‘#ratingsDataset’);
currentItem = ds.getCurrentItem();
//Increment the number of views on this item
let views = ifNull(currentItem.viewCount) + 1;
//In case the number of votes is null, set it to zero
let votes = ifNull(currentItem.voteCount);
ds.setFieldValue('viewCount', views);
ds.setFieldValue('voteCount', votes);
ds.save();
}
export function vectorHeart_click(event) {
$w(‘#vectorHeart’).hide();
$w(‘#vectorHeartRed’).show();
//increment the number of votes and save it
let votes = ifNull(currentItem.voteCount) + 1;
ds.setFieldValue('voteCount', votes);
ds.save()
}