I’m working on a social media-style app where users can like posts. I’m using Recycling List View to display the posts and Firebase Realtime Database to store user data.
Here’s what I want to achieve:
Suppose there are two posts: Post1 and Post2.
User1 likes Post1.
User2 likes Post2.
When User1 reopens the app, they should see Post1 as already liked.
When User2 reopens the app, they should see Post2 as already liked.
So, the like status should be saved per user and loaded correctly when the app restarts.
I want to implement this using Firebase. I already have the basic structure of posts and user accounts working.
My question is:
What’s the best way to structure the Firebase database to achieve this?
How can I link the liked status with the correct user and display it correctly in the Recycling List View?
Any tips, examples, or blocks would be really appreciated!
when Screen1.Initialize
call FirebaseDB1.GetValue with tag = “Posts”
2. When post loaded
when FirebaseDB1.GotValue
if tag = “Posts”
set global posts = value
call FirebaseDB1.GetValue with tag = join “UserLikes/” get current_user_id
3. When FB got Value
when FirebaseDB1.GotValue
if tag = join “UserLikes/” get current_user_id
set global userLikes = value
for each postId in dictionary keys of global posts
create card using DynamicComponents
set label to global posts[postId].content
if global userLikes[postId] exists
set like icon to “liked”
else
set like icon to “unliked”
4. User likes the post
when LikeButton.Click
if post is already liked
call FirebaseDB1.RemoveValue tag = “UserLikes/userID/postID”
decrease post.likesCount in Firebase
else
call FirebaseDB1.StoreValue tag = “UserLikes/userID/postID” value = true
increase post.likesCount in Firebase
5. when Like Button is Clicked
if post is already liked
call FirebaseDB1.RemoveValue tag = “UserLikes/userID/postID”
decrease post.likesCount in Firebase
else
call FirebaseDB1.StoreValue tag = “UserLikes/userID/postID” value = true
increase post.likesCount in Firebase