How can I hide the users with zero points from the leaderboard?

Hi everyone,

I have an app that’s heavily focused on awards and I have a leaderboard screen that I need to update so I can hide from view the users with zero points and only display users that have at least one point in their score, can this be done?
Is there a JS code snippet someone can share with me?

Hi Carina, on the page Leaderboard we have 2 LFD witch are loading the same data.
We need a way to separate those two LFDs, so:

1. At the top of the page add:
var firstLoad = true;

2. At the end of flListDataAfterGetData hook, add:

_.remove(options.records, function(el) {
  return el.data[firstLoad ? 'contributorScore' : 'commentScore'] == 0;
});
firstLoad = !firstLoad;

Thank you Veljko

I tried this bit of code and Studio gave me an error saying “Options is not defined”
The code didn’t work for me.

Based on the error I assumed I pasted the code in the wrong place, I managed to update this in a way that removed the popup error “Options is not defined”, but the code still isn’t working as all the users are still there despite having zero points.

Here’s the full code snippet:

Fliplet.Hooks.on('flListDataAfterGetData', function (options) {
	return Fliplet.DataSources.connectByName(DS.awardLogs).then(function (
		connection
	) {
		return connection.find().then(function (records) {
      var achievementsLength = 0;
			_.forEach(options.records, function (value) {
				var temp = _.find(records, function (o) {
					if (value.data.Email) {
            achievementsLength = o.data.achievements.length
						return o.data.user.toLowerCase() === value.data.Email.toLowerCase();
					}
				});
        
				if (temp !== undefined) {
					var points = 0;
					var commentPoints = 0;
					_.forEach(temp.data.logs, function (record) {
						if (!record.id.includes('comment')) {
							points = points + parseInt(record.points);
						} else {
							commentPoints = commentPoints + parseInt(record.points);
						}
					});
						//_.set(o, 'data.achievementsLength', achievementsLength);
						_.set(value, 'data.achievementsLength', achievementsLength);
					_.set(value, 'data.contributorScore', points);
					_.set(value, 'data.commentScore', commentPoints);
				} else {
						//_.set(o, 'data.achievementsLength', 0);
						_.set(value, 'data.achievementsLength', 0);
					_.set(value, 'data.contributorScore', 0);
					_.set(value, 'data.commentScore', 0);
				}
			});
       options.records = options.records.sort(function (b, a) {
        return a.data.achievementsLength - b.data.achievementsLength;_.remove(options.records, function(el) {
  return el.data[firstLoad ? 'contributorScore' : 'commentScore'] == 0;
});
firstLoad = !firstLoad;
      })
		});
	});
});

Can you help me figure out if I pasted the code in the wrong place?

Hi Carina, yes, you have place it at the wrong place, inside the .sort().
Please replace the whole sort function with this

options.records = options.records.sort(function(b, a) {
return a.data.achievementsLength - b.data.achievementsLength;
});

_.remove(options.records, function(el) {
return el.data[firstLoad ? ‘contributorScore’ : ‘commentScore’] == 0;
});

firstLoad = !firstLoad;

Thanks, this hid the number 0 from the score on the list view of the directory LFD on my screen but the users are still shown on the LFD, I want to hide the users not just the score, is this possible?

I pasted the code inside the sort condition as you’ve mentioned ` options.records = options.records.sort(function (b, a) {
options.records = options.records.sort(function(b, a) {
return a.data.achievementsLength - b.data.achievementsLength;
});

_.remove(options.records, function(el) {
return el.data[firstLoad ? ‘contributorScore’ : ‘commentScore’] == 0;
});

firstLoad = !firstLoad;`