Display certain buttons in repeater, onItemReady, itemData.

I’m using a repeater to display comments made by different users, I created an edit button in the repeater so every registered user gets to edit their own comments after post if they so choose to. Problem is everyone is able to click on any edit button wether they typed the comment or not, how do I show only the buttons for the comments made by the current user viewing the page and hide the others? Is that possible?
Here’s what I got:

  1. I’m working on dynamic page, the URL contains the user id.
    2.The user’s image, email, ID, etc… are being stored in the ‘Afiliados’ collection.
  2. I set the button to be hidden on load and enabled it by default in the properties panel.
  3. The comments are being stored in my ‘Comunidad’ collection, as a result each comment has its own URL and its own ID (that’s separate from the user id)
  4. When each user makes a comment the user id gets inserted in the title field of my ‘Comunidad’ collection and an ID is also generated for each comment.

import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {

const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn) {
currentUser.getEmail().then(email => {
  wixData.query('Afiliados').eq('email', email).find()
	then(() => {
		$w("#repeater1").onItemReady( ($w, itemData) => {
  itemData=$w("#button13").show();
});
});
});
}
});

When I view the page I can see the repeater is showing all of the edit buttons and not just the ones that belong to the comments made by the current user.


Could anyone help me out on this one please?
Thanx

3 Likes

I know this is an old post but in case you never found the answer, I found Yisrael’s comment here to be helpful after four days of searching for an answer and lots of trial and error!

I used his advice to write my code like this, which finally worked:

let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”

$w.onReady( () => {
// show edit button to user who submitted comment only
$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
console.log(itemData.user); // show data from field “user” which is the id in dev console
if (itemData.user === userId) { //this is checking the user field and comparing it to userId from above
$w(‘#editButton’).show();
} else {
$w(“#editButton”).hide();
}
});
}

the link in this comment is dead