-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommunity_page.py
More file actions
44 lines (35 loc) · 1.79 KB
/
Copy pathcommunity_page.py
File metadata and controls
44 lines (35 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as sl
from modules import display_my_custom_component, display_post, display_genai_advice, display_global_leaderboard, display_friends_leaderboard,post_creation_box, add_friend_box
from data_fetcher import get_user_posts, get_user_profile, get_genai_advice, get_user_friends,get_friends_calories_list,get_global_calories_list, insert_user_post, get_global_distance_list, get_global_steps_list, get_friends_distance_list, get_friends_steps_list
def display_community(user_id):
sl.title("Community Page")
user_profile = get_user_profile(user_id)
sl.subheader(f" {user_profile['full_name']}'s")
tab1, tab2, tab3 = sl.tabs(["👥 Friends' Posts", "GenAI Advice", "👤 My Posts"])
with tab1:
add_friend_box(user_id)
if len(get_user_friends(user_id)) <= 0:
sl.info("You haven't added any friends yet!")
else:
sl.markdown("---")
display_post(user_id)
with tab2:
display_genai_advice(user_id)
with tab3:
user_posts = get_user_posts(user_id)
if user_posts:
post_creation_box(user_id)
sl.markdown("---")
user_posts.sort(key=lambda post: post.get('timestamp', ''), reverse=True)
# Generated by GPT 4o
for post in user_posts:
# sl.write(post) #For debugging
image_url = post.get('image', '')
if image_url and image_url.startswith("http"):
sl.image(image_url, width=300)
sl.markdown(post.get('content', 'No content available.'))
timestamp = post.get('timestamp', '🕒 No timestamp')
sl.markdown(f"**{timestamp}**")
sl.markdown("---")
else:
sl.info("You haven't posted anything yet.")