Hi All,
After seeking through the articles on here, I have not been able to find a solution - I’m hoping you can help!
I would like to allow users to comment on a repeater item. I have added an text input and submit button as well as a text box and image to show the users comment and their profile photo. I have also created a collection, #repeaterComments where the comments are saved, with fields comment, userId, profilePhoto and originalPostId (The original post is saved under collection #marks).
The issue is that you can’t add a repeater within a repeater and tables don’t allow you to customise them fully. So I’m wondering how is best to display the comments?
I’ve tried several codes to save the data to no avail. I will also need to enable the user to edit or delete their comment on the repeater card itself, as well as allow users to reply to other comments.
This is what I’ve tried:
Comments Collection = #repeaterComments
Data for repeater collection = #marks
repeater = #repeater1
Submit comment button = #commentButton1
Input comment textbox = # commentInputBox1
Display comment textbox = #comment
let findArray = [];
$w("#repeater1").onItemReady(($item, itemData, index) => {
wixData.query("repeaterComments")
.eq("userId", wixUsers.currentUser.id)
.find()
.then((results) => {
let items = results.items;
for (var i = 0; i < results.items.length; i++) {
var array = items[i].mark;
findArray.push(array);
if (findArray.find(el => el === itemData._id) !== itemData._id) {
$item("#comment").hide();
} else {
$item("#comment").show();
}
}
});
$item('#commentButton1').onClick((event) => {
let toInsert = {
"mark": itemData._id,
"userId": wixUsers.currentUser.id,
"profilePhoto": itemData.mymarks[0].profilePhoto,
"name": itemData.mymarks[0].fullName,
"comment": $item('#commentInputBox1').value,
}
wixData.insert("repeaterComments", toInsert)
.then((results) => {
$item('#comment').show();
$item('#comment').value === itemData.repeaterComments[0].comment;
})
.catch((err) => {
let errorMsg = err;
});
})
})
Thanks in advance!
Paulo