I am currently working on a lists/tasks application and have encountered an issue with counting the items for each list. I am using a session to store which list I am clicking on, but the count system is only related to that specific list. I followed the Meteor task board tutorial to determine how many items I have, but now I need to display the counter in front of each item in every list.
My main challenge lies in understanding how to count the items for each list and display the counter accordingly. In the tutorial, the counter is stored in Session. Should I create a new "counter" in the collection or continue using the session?
Below is some code snippet:
if (Meteor.isServer) {
Meteor.publish('lists', function listsPublication() {
return Lists.find({
$or: [
{private: { $ne: true}},
{owner: this.userId},
],
});
});
}
Meteor.methods({
Template.list.helpers({
incompleteCount() {
return Tasks.find({ listId: Session.get('listId'), checked: { $ne: true } }).count();
},
Template.list.events({
'click .list-selected' (event) {
event.preventDefault();
var list = $(event.currentTarget).attr('list-id');
Session.set('listId', list);
},
Body.js
Template.body.helpers({
tasks() {
const instance = Template.instance();
if (instance.state.get('hideCompleted')) {
return Tasks.find({
listId: Session.get('listId'),
checked: { $ne: true },
}, { sort: Session.get("sort_order") });
}
return Tasks.find({listId: Session.get('listId')}, { sort: Session.get("sort_order")});
},
lists() {
return Lists.find({}, { sort: { createdAt: -1 } });
},
});
Any help or guidance would be greatly appreciated.