Change Icon when Clicked?

My users can “like” each other’s profiles. There is the Open Heart Icon and a # next to it to show how many likes they have. The idea is to click the open heart icon, the # updates and the icon changes to the full? heart icon.

This way I can say “+1 to likes only when icon = open heart icon” This would prevent people from just clicking 100x. I want them to only be able to do this once

First, you need to save in your database somehow which User has ‘liked’ which other User’s profile.

Then just use a conditional on the icon to change it from an empty heart to a full heart when the Current User has liked the particular User’s Profile.

Also use conditionals on your workflow actions and/or on the icon itself to ensure a User can only ‘like’ something once.

hmm. This is difficult to wrap my head around.

So when a user likes another user’s profile. It should store that user’s profile in a list I assume? and then on the “View profiles I like” page, it would need to display all the profiles in an RG.

I am not sure how to do this.

Also, I set the condition
image
To change the icon when pressed. It changes it briefly and then back to the open heart. It also doesn’t update the # of likes.
image
This works however IF I remove the conditional.

Thanks for the help BTW. :slight_smile:

You could do that, but it’s probably not the recommended way to do it (for performance reasons)…

A better approach is probably to create a separate datatype for ‘likes’, with a field for the User who’s liking, and a field for the User being liked (and if your users can like other things beside just other users, have fields for those things as well).

and then on the “View profiles I like” page, it would need to display all the profiles in an RG.

Yes, if that’s what you’re trying to do.

To change the icon when pressed. It changes it briefly and then back to the open heart.

Yes, indeed… the condition ‘is pressed’ is only true whilst the User’s mouse button is held down…

In any case, that’s irrelevant here…

Your conditional needs to be based on whether or not the Current User has liked the User’s profile (not whether or not the mouse button is being held down)… so depending on how you’re storing the ‘Like’ in your database it might be when: search for Likes: 'User = Current User' and 'Liked User = Parent Group's User': count < 0 Change the icon to a full heart and make the element unclickable

1 Like

So I got it to add the current user’s username to the list when they click the icon. It displays the count of that list as well in the text next to it.

All I have now is the conditional, which I can’t get right.
image
I have it set to search “Builds” which is where the liked users list is stored. To me this says When “Builds” contains the Current User’s Username, then change the icon. but it doesn’t like that.

I don’t know how your database is set up, (so I can only really guess)… but, assuming you’re storing actual Users on the list (and not texts) then you don’t want to use Username, just the User itself… but it depends on how your database is set up…

As it is, that expression doesn’t make sense… hence why it’s red… it needs to evaluate to a yes/no.

Again, without knowing how your database is set up i can’t be very specific, but assuming you’re using a list to store the users who have liked whatever it is they’re liking (which as I said previously, is not the best way to do it), you’ll just want to say when the Buildss’s list of Users contain the current user.

Or, if you’re doing it the other way round, then use ‘when the current users list of liked things contains the thing’.

ah I gotcha. So I changed it to store the User on a list of Users rather than the username on a list of text.


This adds the email of the user that clicks “Like”


I feel like I am on the right track though.

1 Like

It doesn’t add the email (which is a text), it adds the User itself… (it might display the email on your data tab, if that’s what you’ve got it set to display, but it’s the actual User object that’s being added to the list)…

You don’t need to do a search for Buildss if you’re referring to the current page Builds…

So get rid of the 'Search for Buildss contains the current User (that doesn’t make any sense anyway - a search for Buildss will return a list of Buildss, so it can’t contain a User)…

And just use when: current page's Builds's Users That Liked contains Current User

1 Like

ah okay that makes more sense now. It works perfect! This clarified things how to do the reverse as well - remove the like when clicked.

Now to figure out how to display profiles I’ve liked on another page. And that’s when things get really complicated

Thanks again, I’m sure I’ll be asking a million other things in the future :laughing:

1 Like