Hi Shlomi,
Thank you so much for your help so far. Things are finally starting to come together, however I don’t completely understand what I have to do now. I have read the article you linked to your post, but I am still confused as to what it is I must do and how to achieve it. Maybe step-by-step instructions? Sorry if I’m asking too many questions, but I am fairly new to all of this
Thanks!
please consider adding permissions to the page Wix Editor: Creating Members Only Pages | Help Center | Wix.com otherwise even non site members can follow other site members but you have no information at all about them, so i am not sure it makes sense, wdyt?
then in the relationship collection use data of type reference to the profile collection
when using wix-data insert you should use the profile _id, but when viewing this collection you will see the column which you configured as primary field in the profile collection (currently title)
try creating some profiles which are using the members area login and fill the collections with some sample data
OK, thanks for the clarification!
Hi,
I have created a test profile and filled the filled the “Followers_Followees” collection with sample data.
cool, now do we want to allow even non site members to follow such profiles? not sure it makes sense or not
I don’t think we should allow non site members to follow other registered users.
in that case, consider adding permissions to the page so only logged in users can see it, you need the context of current user to add it in the wix-data insert to the data base. and also to know if you should enable/disable the follow button in case the user follows that profile already
Hi Shlomi,
I got this code from an old forum post:
import wixData from “wix-data”;
$w.onReady(function () {
// tell the repeater you want to update each item when it’s ready
$w(“#repeater1”).onItemReady(function($w, itemData, index) {
// get the userId of the item (i.e. the followee)
const followeeId = itemData._owner;
// find all the records where followee === followeeId
wixData
.query("Following")
.eq("followee", followeeId)
.find()
.then(function (results) {
// assign the number of results to your "counter" text elemnt
$w("#text91").text = results.totalCount; //
results.length
});
});
});
Could this be used for the counter on the repeating layout? If so, what should I do?
If this can be used, i am confused with the “assign the number of results to your “counter” text element”. How do I do that?
Hi,
in one of the previous posts i suggested the code above as a good starting point. it will work!
however please note that for 20 results you will invoke the db 20 times which may result in page load latency. another way to do it, is add a counter column to your profile collection, and each time a follower is added to a profile, you increment it by one, and so, you already have the result in the profile collection which you can just use as a text in the repeater, connect it to that new column
makes sense?
shlomi
Hi,
What do you mean by “counter column?”
Just a name, can be num_followers which you keep updated, on click of ‘follow’ button
Hi,
I can’t figure out how to do this. Does this require a code?
I am having trouble figuring out how to add a counter column to my profile collection so that each time a follower is added to my profile, I increment it by one. How does that work?
Hi,
in the follow button on click, after the successful insert to the relationship collection, you can query the profile table, filtered by the profile that was chosen to follow, and wix-data update the profile’s item in the collection.
again, this is an improvement, please try to get to a working-page state first you are very close
shlomi