Added support for liking/disliking posts with like counter
Browse files
app.py
CHANGED
@@ -91,7 +91,7 @@ def get_posts_for_topic():
|
|
91 |
posts = client.get_posts_for_topic(topic)
|
92 |
st.write(f"Posts for topic '{topic}':")
|
93 |
for post in posts:
|
94 |
-
st.markdown(
|
95 |
|
96 |
|
97 |
def get_trending_topics():
|
@@ -132,16 +132,26 @@ def get_all_posts():
|
|
132 |
all_posts.append((user_name, post))
|
133 |
sorted_posts = sorted(all_posts, key=lambda x: x[1].timestamp)[::-1]
|
134 |
for user_name, post in sorted_posts:
|
135 |
-
st.
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
|
147 |
def main():
|
|
|
91 |
posts = client.get_posts_for_topic(topic)
|
92 |
st.write(f"Posts for topic '{topic}':")
|
93 |
for post in posts:
|
94 |
+
st.markdown(post)
|
95 |
|
96 |
|
97 |
def get_trending_topics():
|
|
|
132 |
all_posts.append((user_name, post))
|
133 |
sorted_posts = sorted(all_posts, key=lambda x: x[1].timestamp)[::-1]
|
134 |
for user_name, post in sorted_posts:
|
135 |
+
liked = st.session_state.current_user in post.liked_by
|
136 |
+
like_button_label = "👍" if not liked else "👎"
|
137 |
+
|
138 |
+
col1, col2 = st.columns([4, 1])
|
139 |
+
with col1:
|
140 |
+
st.markdown(
|
141 |
+
f"""
|
142 |
+
<div class="post-container">
|
143 |
+
<div class="post-header">{user_name}</div>
|
144 |
+
<div class="post-content">{post.content}</div>
|
145 |
+
<div class="post-timestamp">{post.timestamp}</div>
|
146 |
+
<div class="post-likes">Likes: {post.likes}</div>
|
147 |
+
</div>
|
148 |
+
""",
|
149 |
+
unsafe_allow_html=True,
|
150 |
+
)
|
151 |
+
with col2:
|
152 |
+
if st.button(like_button_label, key=f"like_{post.timestamp}"):
|
153 |
+
client.like_post(st.session_state.current_user, post.timestamp)
|
154 |
+
st.rerun()
|
155 |
|
156 |
|
157 |
def main():
|