Skip to content

Commit bc944a0

Browse files
committed
style: Clean decimal precision and sync sidebar profile pic
1 parent f64a353 commit bc944a0

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

frontend/components/sidebar.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,26 @@ def render_sidebar():
5050
if username != 'Guest':
5151
with st.container():
5252
# Simple clean profile display
53-
st.markdown(f"""
54-
<div style="background-color: rgba(255, 255, 255, 0.05); padding: 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; margin-bottom: 20px;">
53+
# Simple clean profile display with Dynamic Picture
54+
pic = st.session_state.get('profile_picture')
55+
56+
avatar_html = ""
57+
if pic:
58+
avatar_html = f"""
59+
<div style="width: 38px; height: 38px; border-radius: 50%; overflow: hidden; border: 2px solid #3B82F6;">
60+
<img src="{pic}" style="width: 100%; height: 100%; object-fit: cover;">
61+
</div>
62+
"""
63+
else:
64+
avatar_html = f"""
5565
<div style="background: #3B82F6; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; color: white;">
5666
{username[0].upper()}
5767
</div>
68+
"""
69+
70+
st.markdown(f"""
71+
<div style="background-color: rgba(255, 255, 255, 0.05); padding: 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; margin-bottom: 20px;">
72+
{avatar_html}
5873
<div>
5974
<div style="font-weight: 600; font-size: 14px; color: #F1F5F9;">{username}</div>
6075
<div style="font-size: 12px; color: #4ADE80;">● Online</div>

frontend/utils/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ def login(username, password) -> bool:
8181
st.session_state['username'] = username
8282
save_session(token, username)
8383

84-
# Fetch profile to get Role
84+
# Fetch profile to get Role and Picture
8585
try:
8686
prof = fetch_profile()
8787
if prof:
8888
st.session_state['role'] = prof.get('role', 'patient')
89+
st.session_state['profile_picture'] = prof.get('profile_picture')
8990
except:
9091
pass
9192

frontend/views/profile_view.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def render_profile_page():
4141
with col_inputs:
4242
col1, col2 = st.columns(2)
4343
with col1:
44-
height = st.number_input("Height (cm)", value=float(profile.get("height") or 170.0))
45-
weight = st.number_input("Weight (kg)", value=float(profile.get("weight") or 70.0))
44+
height = st.number_input("Height (cm)", value=int(profile.get("height") or 170), format="%d", step=1)
45+
weight = st.number_input("Weight (kg)", value=float(profile.get("weight") or 70.0), format="%.1f", step=0.1)
4646
diet = st.selectbox("Diet", ["Vegetarian", "Non-Vegetarian", "Vegan", "Keto", "Other"], index=0 if not profile.get("diet") else ["Vegetarian", "Non-Vegetarian", "Vegan", "Keto", "Other"].index(profile.get("diet")))
4747
with col2:
4848
activity = st.selectbox("Activity Level", ["Sedentary", "Lightly Active", "Moderately Active", "Very Active"], index=0)
49-
sleep = st.slider("Sleep (Hours)", 4.0, 12.0, float(profile.get("sleep_hours") or 7.0))
49+
sleep = st.slider("Sleep (Hours)", 4.0, 12.0, float(profile.get("sleep_hours") or 7.0), step=0.5, format="%.1f")
5050
stress = st.selectbox("Stress Level", ["Low", "Moderate", "High"], index=1)
5151

5252
allow_data = st.checkbox("Allow Data Collection for AI Improvement", value=profile.get("allow_data_collection", True))
@@ -70,8 +70,10 @@ def render_profile_page():
7070
"stress_level": stress, "allow_data_collection": allow_data,
7171
"profile_picture": pic_data
7272
}
73-
api.update_profile(payload)
74-
st.rerun()
73+
if api.update_profile(payload):
74+
# Update Session State immediately for Sidebar sync
75+
st.session_state['profile_picture'] = pic_data
76+
st.rerun()
7577

7678
# Display Metrics
7779
st.markdown("### My Stats")

0 commit comments

Comments
 (0)