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, however every registered user is able to click the edit button every time whether they typed the comment or not. How do I enable only the buttons for the comments made by the current user and disable the others? Is that possible?
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Guess somethings just stay unanswered on this forum.
Someone from the Wix team is needed here please. Anyone?
No luck. It's still doing the same thing. :(
You write now that you store the users ID in the title field in the data collection? If that is true the query you run will not find anything. Change it.
wixData.query('Afiliados')
.eq('title', ID)
Test that
I've been trying all sorts of different things. This is what I got now:
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.
3. I set the button to be hidden on load and enabled it by default in the properties panel.
4. 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)
5. 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 wixUsers from 'wix-users'; import wixData from 'wix-data'; $w.onReady(function () { let currentUser = wixUsers.currentUser; if (currentUser.loggedIn) { currentUser.getEmail().then(ID=> { wixData.query('Afiliados','_id') .eq('_id', ID) .find() .then(() => { $w("#repeater1").forEachItem( ($w, itemData) => { $w('#button9').show() (itemData.currentUser.loggedIn); }); }); }); } });
I gotta tell you now, I'm quite confused....
This code is only showing me the button that's on the top comment and not the ones that are on the comments the current user made, which is what I want it to do.
I hope I'm making myself clear. This is all new to me and I don't understand it fully. But believe me, I'm trying. :(
You are still searching the data collection for email field but you wrote that it is the users id you store?
This is what I got so far:
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $w('#button9').hide(); $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) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } }); }); }); } });
This time it is showing all the buttons and not just the current user's . It seems that the lines below are not doing anything at all but the rest of the code is working:
$w("#repeater1").onItemReady( ($w, itemData) => { if (itemData.currentUser.loggedIn) {
Actually, it's not working at all.
This code shows all the buttons but I need it to only show the buttons for the comments the current user made:
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $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) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } else { $w("#button9").hide(); } }); }); }); } });
Nope. It's not working. This is what I did:
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $w.onReady(function () { const currentUser = wixUsers.currentUser; if (currentUser.loggedIn) { currentUser.getEmail().then(currentUser => { wixData.query('Afiliados').eq('_id', currentUser).find() .then(() => { $w("#repeater1").onItemReady( ($w, itemData) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } else { $w("#button9").hide(); } }); }); }); } });
Ok, but you are filtering the dataset on email?
wixData.query('Afiliados').eq('email', email).find()
Maybe should be
wixData.query('Afiliados').eq('_id', currentUser).find()
Still not working... :(
The userid is stored in the 'Afiliados' collection as ID, field key _id. The id for each individual comment is stored in the 'Comunidad' collection as ID, field key _id as well. These ID's are created automatically. The userid is also inserted in the 'Comunidad' collection in the tittle field everytime a user makes a comment. I hope I'm explaining myself thoroughly.
ok, try this
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $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) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } else { $w("#button9").hide(); } }); }); }); } });
Also tell me what name is the field in the comments data collection that holds then userid? Or do you just store email?
It hides all the buttons and not just the ones that do not belong to the current user.
I don't get any.
What error do you get in the developer console?
It's still not working. I am soooooo confused! :(
Hey
I just find that you are missing a closing } in the end. Try this
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $w.onReady(function () { $w("#button9").hide(); }); const currentUser = wixUsers.currentUser; if (currentUser.loggedIn) { currentUser.getEmail().then(email => { wixData.query('Afiliados').eq('email', email).find() .then(() => { $w("#repeater1").onItemReady( ($w, itemData) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } }); }); }); }
You might want to run the whole code within the onReady function to make sure the page is fully loaded.
Like the below:
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $w.onReady(function () { $w("#button9").hide(); const currentUser = wixUsers.currentUser; if (currentUser.loggedIn) { currentUser.getEmail().then(email => { wixData.query('Afiliados').eq('email', email).find() .then(() => { $w("#repeater1").onItemReady( ($w, itemData) => { if (itemData.currentUser.loggedIn) { $w('#button9').show(); } }); }); }); } });
Anyone?
Here's another version of the code:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
$w("#button9").hide();
});
const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn) {
currentUser.getEmail().then(email => {
wixData.query('Afiliados').eq('email', email).find()
.then(() => {
$w("#repeater1").onItemReady( ($w, itemData) => {
if (itemData.currentUser.loggedIn) {
$w('#button9').show();
}
});
});
});
Still not working. :(