Read and write using the dame data collection

Hello,
I’m trying to create 2 different pages with a rating elements that will read and write using the same data base.
That way, if someone rate the same item in 2 separate pages on the web site, the rating of the item stays updated and will show the same value on both pages.

Will appreciate an advice on how to do so.

Thanks
Yonatan.

@barefootexpert Can you explain a little more what you are trying to do? My current guess is that you are trying to enable update to the views presented on different screens looking at the web site? So If you are on the site and I am on the site and we are looking at the same page and I change a rating, you want to be able to see my update?

Is that the use case or do you have a different concept in mind?

hi steve,

actually, after tryng to hire a developer that kinda failed to understand then implement again, it appears to be more complicated. i was thinking we can use the comments app for what i had in mind, but it’s not possible.

here is a more detailed explanation:

  1. what i call in index page
    https://www.happybarefoot.com/minimal-barefoot-shoes-directory
    this is actually a page that shows a list of all items in the collection DB have created. a table connected to a dataset.

  2. item pages
    which is a dynamic page created with data from the same collection DB.
    if you press the “go to website” button under of the items in the index page, you will navigate to the item dynamic page. see img attached.


now, i wanted in the item page, meanig the dynamic page of an item from the collection, that the users will be able to rate and comment.
then, in the index page, that the useres will see the sumarry of ratings, as in th epicture below:


the issues we have now are:

  1. the comment app docent support dynamic pages, unless it a’s a blog
  2. the developer couldn’t read the value summary to the index page, that is why i posted the question. now he did find a solution. but:
    2.2. there are no options to comment
    2.3. there is no user verification that prevent 1 user to vote endless times, as there is in the wix comment app.

so, i’m not sure, but i might need to redesign the whole website ):
unless maybe you have a lead on a simpler solution.

thanks
yonatan.

import wixUsers from “wix-users”;

$w.onReady(function () {

//place a post comment button on the page and call it commentButton1 

$w('#commentButton1').onClick(function () { 

    //dataset1 is connected to your collection where you store the original post 

    let orininalPostId = $item("#dataset1").getCurrentItem()._id; 

    //dataset2 is connected to your collection where you store the comments, make sure you have set read/write access to dataset2 

    $w("#dataset2").onReady(() => { 

        let user = wixUsers.currentUser; 

        //get userEmail so that it can be passed to the comments database that way we know who made the comment 

        user.getEmail() 

            .then((email) => { 
                let currentUserEmail = email; 

                //create columns in your comments database and name them orininalPostId, comment, userEmail. Place an comment input box on the page and call it commentInputBox1   

                //now we save the comment to the database 

                $w('#dataset2').setFieldValue('orininalPostId', (orininalPostId)); 
                $w('#dataset2').setFieldValue('comment', $w('#commentInputBox1').value); 
                $w('#dataset2').setFieldValue('userEmail', (currentUserEmail)); 
                $w('#dataset2').save() 

            }) 
    }) 
}) 

})

thanks mike!
will check it out

@barefootexpert I think Mike’s suggestion is along the right lines. Now several things to consider.

  1. In Mike’s suggestion you may need to wrap the onClick function in a $w(" #dataset1 ").onReady() function call. As a matter of style I normally declare event handlers independently of other handlers (in this example declaring an onReady inside of an onClick means the onReady doesn’t get called until the onClick has been called at least once). I would pull this out and put it in the same scope as the onClick.

  2. Do you want to aggregate ratings or simply using the last rating that a site visitor adds? If you are aggregating then you will need to save the ratings as Mike suggests and then run a dataCollection aggregation call on the ratings values you add to get an average (assuming this is your idea) back to display in your summary rating.

  3. Mike’s suggestion assumes that you have the visitor registered on your site. Otherwise you will not have access to their email address. This is a wise move because you can ultimately block access if you discover a user misusing the comments feature you build to leave inappropriate comments.

  4. PLEASE NOTE: As soon as you start collecting information from users you will be subject to Data Protection Laws not only of your country but sometimes the country where the visitor to your site resides. So think about the policies and disclosures etc. you need there.

If you need further help on this in the forum then you should share your code and the structure of your data collection(s). Also - often not considered, if you have linked the dataset to a control in the editor and this isn’t clear in your post then suggested solutions may not work as expected.

Good luck.