Add a user's likes

I want to add current user’s like to a list of likes (Users) when the heart icon is clicked, i also want to change the icon color to red when that current user is in that list and back to blank when the current is not in that list

Thanks to anyone that can help

You literally just explained your own workflow.

5 Likes

yeah…i have the idea of what to do but dont know how to

When someone clicks the heart icon, just add the current user’s like to the list of likes.

Then set a condition on the icon such that when the current user is in that list the icon is red.

Screenshot 2023-07-13 044220

Something like this right?

Yeah, that looks about right…

1 Like

I did something very similar, only to take it to the next level, instead of adding a ‘user’ to a list on a ‘thing’ they liked, I created a separate datatype, ‘Likes’, and when they ‘liked’ something it would create a Like with User, Thing, and ‘Yes/no’. It then adds a ‘+1’ to the total of ‘likes’ on a number field I have on the thing. If they have already liked the thing, it changes the ‘Yes’ to a ‘No’, and subtracts ‘1’ from the likes total. This prevents items that (hopefully) would get thousands of likes from being bogged down with a long list.

ok…this means you deleted the “likes” from the data field under "user’
And made a separate datatype for “Likes”
🥲

1 Like

Correct! It was simpler than it sounds, and creating a ‘like’ datatype gives you a lot more control over it. For example, on a list of ‘things’, I can show the items a user liked, simply by restricting permissions on ‘Likes’ to the user that created them - so MUCH easier on WU as well (at least my understanding). Also gives you the ability to track exactly when a user liked something (or un-liked it), triggering workflows based on the Like action, etc.

In my case, i added the “Likes” data field under my post datatype and i want to add a user to the list of users under the “likes” data field when a user clicks on the “heart” icon

i can’t seem to do that

I think i’m going to go with your approach and see what happens

thanks for this :fire:

1 Like

For your use-case, and how your data is setup, it should be something like:

When user clicks heart icon → Make changes to a thing → thing to change: Current Post → Likes: Add List “Current User”. This will add the current user to the list of likes on your type ‘Post’.

This is the approach I was encouraged to take, again mostly to prevent performance issues if a LOT of people like the same thing (which would lead to a long list, something we’re encouraged to avoid). But once I did it, I found the flexibility was powerful as well.

i actually did this at first but didn’t get any result

I would check your permissions, and make sure you’re logged in as a user.

Here I use a data type approach to likes. Same as the video above. For each new like, an item is created in the database. Because if we inserted users into a list in the like item itself, this list would get very long over time.

1 Like