So the repeater is showing data from TRIPOLI dataset(filtered).
repeater has a button which will add products to cart, on ready i need the labels of the buttons to change accordingly it has to be something like this;
it will take title of each item and see if they are in the Shoppingcart dataset and the ones that matches will be labeled remove and rest add.
currently this is how i add and remove from Shoppingcart dataset
export function addq_click(event) {
let user = wixUsers.currentUser;
let userId = user.id;
const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater.
wixData.query("TRIPOLI") // get the item from the database collection.
.eq("_id", itemId)
.find()
.then((results) => {
let saveit = results.items[0].title;
let price = results.items[0].price;
let productid = results.items[0].productid;
let toSave = {
"title": saveit,
"price": price,
"productid": productid,
"userId": userId // adding a field of the current user to the database in order to distinguish between other users wishlist.
};
wixData.save("Shoppingcart", toSave);
console.log(saveit);
});
}
let newid= "";
export function negitive_click(event) {
let user = wixUsers.currentUser;
let userId = user.id;
const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater.
wixData.query("TRIPOLI") // get the item from the database collection.
.eq("_id", itemId)
.find()
.then((results) => {
let itemidd = results.items[0];
newid= itemidd.title;
wixData.query("Shoppingcart") // get the item from the database collection.
.eq("title", newid)
.eq("userId", userId)
.find()
.then((results) => {
let remove = results.items[0]._id;
wixData.remove("Shoppingcart", remove);
console.log(remove);
});
});
}
now i want to have one button that change labels and function accordingly