Background: Rating summaries from Wix Comments App were finally connected to a ratings display!!! This was done on dynamic item pages
I’m stuck with replicating this functionality in repeaters of a dynamic list page. This little modification is the FINAL HURDLE for this feature! I’d be grateful for yall that can show how
The working code thus far is thanks to the genius dev @azmat123a. He deserves much support!
// Working code for ***backend web module
import { Permissions, webMethod } from "wix-web-module";
import { comments } from "wix-comments.v2";
import { elevate } from "wix-auth";
const COMMENTS_APP_ID = "91c9d6a7-6667-41fb-b0b4-7d3b3ff0b02e";
let componentId='comp-m8rnvu2d'
export const getAverageRating = webMethod(
Permissions.Anyone,
(resourceId) => {
let id=`${componentId}${resourceId}`;
console.log("Iam id"+resourceId)
return queryComments(id);
}
);
async function queryComments(resourceId) {
const elevatedQueryComments = elevate(comments.queryComments);
const { items } = await elevatedQueryComments(COMMENTS_APP_ID)
.eq("resourceId", resourceId)
.find();
// return items
if (items.length === 0) return 0;
const totalRatings = items.reduce((a, b) => a + (b.rating || 0), 0);
const averageRatings = totalRatings / items.length;
return {
average: averageRatings,
total: items.length
};
}
// Working code for frontend
import { getAverageRating } from 'backend/comments.web'
$w.onReady(async function () {
$w("#dynamicDataset").onReady(async () => {
let itemObj = $w("#dynamicDataset").getCurrentItem();
console.log("hi" + itemObj)
console.log(itemObj)
const link = itemObj._id;
console.log(link); // Output: this-is-a-title-01
const { average, total } = await getAverageRating(link);
// console.log(averageRating)
$w("#ratingsDisplay1").rating = average;
$w("#ratingsDisplay1").numRatings = total;
});
});
Working in Wix Editor
1 Like
Do you have any examples beside the rating? I’m building my own comment widget and I tried filtering with resourceId. It didn’t work,
do you know how to get current dynamic page’s comments using queryComments?
This approach is not via a custom built widget, but using the Wix Comments app. A key ingredient here is getting the componentId by first querying all items by running a modified code on the IDE.
I tried the alternative; building a custom widget but left it cuz the Wix Comments app already had many features I needed. If you want the custom approach check out the YouTube channel @thewixwiz he has a few great tutorials on exactly this
If it still doesn’t work, message me & I’ll have a look
I’ve tried his way before. I want to use the wix api to reduce CMS usage since it will be taking more CMS quota for my website’s requirement . That’s why I choose comment widget, you’re comment is good , I’m applying more conditions to make perfect one
1 Like
@Gideon_Skarzgard in regards to the original request maybe this may work.
import { getAverageRating } from 'backend/comments.web';
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
const items = $w("#dynamicDataset").getItems();
$w("#repeater1").data = items.items;
$w("#repeater1").onItemReady(async ($item, itemData, index) => {
const itemId = itemData._id;
try {
const { average, total } = await getAverageRating(itemId);
$item("#ratingsDisplay1").rating = average;
$item("#ratingsDisplay1").numRatings = total;
} catch (err) {
console.error(`Error loading rating for item ${itemId}:`, err);
$item("#ratingsDisplay1").rating = 0;
$item("#ratingsDisplay1").numRatings = 0;
}
});
});
});
1 Like
the retun value doesn’t have reacted user id. How can I find it for is that no way to add reaction button to custom comment widget?
return only has reaction summary (totalreaction and reaction (key, value))
not sure, I was replying to the original post. Do you have a post you started with the code you are tring ?
Here,
How to get current page’s resourceId or contextId? - Ask the community - Community Support Forum | Wix Studio
The topic is changed but I think I have to stick with Wix comment app widget since the wix comment sdk doesn’t provide reacted member list and rating in updateComment method.
Not clear what you said, were you able to solve your first issues? There’s a native button for reactions in Wix Comments settings. Displaying ratings summaries though are now solved
You did it!! Legendary
stuff as always
Thank you so so much dear @Dan_Suhr. Hope you’ve been well & your foot’s recovered
1 Like
The fetched data don’t have type of reacted members, it’s return reactionSummary but I need reacted people list to filter if current member is reacted or not, and also in updateComment method, I don’t see an option to update reaction. I think they don’t give us the reacted member list so I stopped working on custom comment ,
What I achieved
- Fetch current comments of CMS page using comp Id (I modified it from your code)
- Fetch reaction summary to show which reaction type (:like: , :thinking : ) total, not individually
- Used Rich Content Viewer to display each comment in repeater item,
- added custom CMS to replies (margin)
- Reply function (was going to add before but stopped after reaction problem) also I made the repeater display to have sub replies (by filtering using parentThread)
- each comment’s rating
- Poll Data (was able to show but can’t use since rico editor format and hard to work on it)
- show comment’s author profile photo and nickname , like social medias, using wix-members-backend [FULL] full member dataset’s fields.
If the reacted user list show on each comment in returned data, I would be making something like facebook or instagram comments but wix api gave no options to continue for me. I’ll complete this task if wix comments v2 added this lacking features!
Here is the problem
reaction properties not available in Update comment’s Method Parameters.