Hi. I’m trying to build a wishlist where you can add items. The problem is, that you could add an item multiple times, since there’s no code preventing that. I want to change the button to “already in wishlist” or something similar.
First it should check if the item is already in the database. If it is, the button “addToWishlist” should disappear and the “inWishlist” button should show up. However this doesn’t work. Instead it always says that the item is already in my wishlist and then too, I can’t remove the item from my wishlist.
Please help me. Thanks in advance.
So this is my code:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
if (($w("#itemdetails").setFilter(wixData.filter().contains("myList", { Id: $w('#itemdetails').getCurrentItem()._id })))) {
$w('#addToWishlist').hide()
$w('#inWishlist').show()
} else {
$w('#addToWishlist').show()
$w('#inWishlist').hide()
}
})
export function addToWishlist() {
wixData.insert('myList', { Id: $w('#itemdetails').getCurrentItem()._id }),
$w('#addToWishlist').hide(),
$w('#inWishlist').show();
}
export function inWishlist() {
wixData.remove('myList', { movieId: $w('#itemdetails').getCurrentItem()._id }),
$w('#addToWishlist').show(),
$w('#inWishlist').hide();
}