Like button on repeater limited to login and one click only

Hey all, I’m trying to create a like button on a repeater that requires a login to press and its limited to one click per container. I’ve made one where you don’t need to log in and is limited to one click but when you refresh you can click again. I want to add a limit and a login check/limit to said button. If anyone can point me in the right direction that would help.

I’ve looked at https://www.wixcodebank.com/like-button-to-repeater but that limits it to IP apparently and it also lets you click when you refresh the page. I’ve checked out https://support.totallycodable.com/en/article/count-likes-or-votes-on-a-single-item-dynamic-page-using-wix-code as well but that’s creating a simple like button. Also looked at https://www.vorbly.com/Vorbly-Code/WIX-REPEATERS-LIKE-BUTTONS-FOR-COMMENTS but again, refreshes let you like again and I need a limit to only logged in members.

I know that I need a 2nd database which I’ve made, and I know I need to link them somehow I just can’t make that jump.

Any help would be greatly appreciated!!

import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
var userId;
// disables items previous liked by the same user using IP address
function repeaterSettings(){
$w("#dynamicDataset").onReady(() => {
// stop user from liking the same pages again
wixData.query("LikesforPictures")
.eq("userId", userId)
.limit(1000)
.find()
.then((result) => {
if (result.items.length > 0) {

// check each repeater item to see if it has been liked already
$w("#repeater2").onItemReady( ($item, itemData, index) => {

var i;
for (i = 0; i < result.items.length; i++) {
console.log(result.items[i].title);
if(itemData._id === result.items[i].pageId ){
$item("#btnLike").hide(); $item("#greyLike").show();
}
}
});
}
})
.catch((err) => {
console.log(err);

});
});
}
// registers a new item like
export function btnLike_click(event) {

let $item = $w.at(event.context);
let clickedItemData = $item("#dynamicDataset").getCurrentItem();
// update the repeater in real time
let likes_calc = clickedItemData.likes + 1;
$item("#likesCounter").text = likes_calc.toString();
// hide the like button so it can't be clicked again
$item("#greyLike").show(); $item("#btnLike").hide();
// actually add the like to the collection in the back end
wixData.query("ArtworkAccepted")
.eq("_id", clickedItemData._id)
.limit(1)
.find()
.then((results) => {
let item = results.items[0];
item.likes = item.likes + 1;
wixData.update("ArtworkAccepted", item)
.then(() => {
console.log("Like added");
})
.catch((err) => {
console.log(err);
});

})
.catch((err) => {
console.log(err);
});
}
// takes a like away
export function greyLike_click(event) {

let $item = $w.at(event.context);
let clickedItemData = $item("#dynamicDataset").getCurrentItem();
// update the repeater in real time
let likes_calc = clickedItemData.likes - 1;
$item("#likesCounter").text = likes_calc.toString();
// show the like button so it can be clicked again
$item("#greyLike").hide(); $item("#btnLike").show();
// actually take the like from the collection in the back end
wixData.query("ArtCollectionOld")
.eq("_id", clickedItemData._id)
.limit(1)
.find()
.then((results) => {
let item = results.items[0];
item.likes = item.likes - 1;
wixData.update("ArtCollectionOld", item)
.then(() => {
console.log("Like added");
})
.catch((err) => {
console.log(err);
});

})
.catch((err) => {
console.log(err);
});
}
// saves like history by UserID to disable on next visit
function saveLikes(title, artworkTitle)
{
var toInsert;
toInsert = {
"title": title,
"artworkTitle": artworkTitle,
"UserId": userId
};
// add the item to the collection
wixData.insert("LikesforPictures", toInsert)
.catch((err) => {
console.log(err);
});
}

See the Ratings by User example.

have you find a solution ? i need show liked repeaters on my members page.

@yisrael-wix

Can I use like button on repeater so users can follow who pressed like for them?

@admin67412 You’ll have to make appropriate adjustments to the code, but you certainly should be able to use the data so that users can follow who liked them.

Can you please share with us that code you use to have a like even when you refresh the page thank