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
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.
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
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.
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.