Add support to add post in the same page as viewing posts
Browse files
app.py
CHANGED
|
@@ -69,17 +69,6 @@ def delete_own_user():
|
|
| 69 |
st.error(f"Error: {e}")
|
| 70 |
|
| 71 |
|
| 72 |
-
def add_post():
|
| 73 |
-
st.title("Add Post")
|
| 74 |
-
post_text = st.text_area("Enter post text", placeholder="What's happening?")
|
| 75 |
-
if st.button("Add Post"):
|
| 76 |
-
try:
|
| 77 |
-
client.add_post(st.session_state.current_user, post_text)
|
| 78 |
-
st.success("Post added successfully.")
|
| 79 |
-
except Exception as e:
|
| 80 |
-
st.error(f"Error: {e}")
|
| 81 |
-
|
| 82 |
-
|
| 83 |
def get_posts_for_user():
|
| 84 |
st.title("Get Posts for User")
|
| 85 |
users = client.get_users()
|
|
@@ -89,7 +78,7 @@ def get_posts_for_user():
|
|
| 89 |
posts = client.get_posts_for_user(user_name)
|
| 90 |
st.write(f"Posts for user '{user_name}':")
|
| 91 |
for post in posts:
|
| 92 |
-
st.markdown(
|
| 93 |
except KeyError as e:
|
| 94 |
st.error(f"Error: {e}")
|
| 95 |
|
|
@@ -123,7 +112,19 @@ def get_trending_topics():
|
|
| 123 |
|
| 124 |
|
| 125 |
def get_all_posts():
|
| 126 |
-
st.title("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
posts = client.get_posts()
|
| 128 |
all_posts = []
|
| 129 |
for user_name, user_posts in posts.items():
|
|
@@ -152,18 +153,17 @@ def main():
|
|
| 152 |
page = st.sidebar.selectbox(
|
| 153 |
"Choose an action",
|
| 154 |
[
|
| 155 |
-
"
|
| 156 |
"Delete Account",
|
| 157 |
"Get Posts for User",
|
| 158 |
"Get Posts for Topic",
|
| 159 |
"Get Trending Topics",
|
| 160 |
-
"View All Posts",
|
| 161 |
],
|
| 162 |
-
index=
|
| 163 |
)
|
| 164 |
|
| 165 |
-
if page == "
|
| 166 |
-
|
| 167 |
elif page == "Delete Account":
|
| 168 |
delete_own_user()
|
| 169 |
elif page == "Get Posts for User":
|
|
@@ -172,8 +172,6 @@ def main():
|
|
| 172 |
get_posts_for_topic()
|
| 173 |
elif page == "Get Trending Topics":
|
| 174 |
get_trending_topics()
|
| 175 |
-
elif page == "View All Posts":
|
| 176 |
-
get_all_posts()
|
| 177 |
else:
|
| 178 |
page = st.sidebar.selectbox("Choose an action", ["Login", "Register"], index=0)
|
| 179 |
if page == "Login":
|
|
|
|
| 69 |
st.error(f"Error: {e}")
|
| 70 |
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def get_posts_for_user():
|
| 73 |
st.title("Get Posts for User")
|
| 74 |
users = client.get_users()
|
|
|
|
| 78 |
posts = client.get_posts_for_user(user_name)
|
| 79 |
st.write(f"Posts for user '{user_name}':")
|
| 80 |
for post in posts:
|
| 81 |
+
st.markdown(post)
|
| 82 |
except KeyError as e:
|
| 83 |
st.error(f"Error: {e}")
|
| 84 |
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
def get_all_posts():
|
| 115 |
+
st.title("Feed")
|
| 116 |
+
|
| 117 |
+
# Add post section at the top
|
| 118 |
+
post_text = st.text_area("What's happening?", key="new_post_text")
|
| 119 |
+
if st.button("Add Post"):
|
| 120 |
+
try:
|
| 121 |
+
client.add_post(st.session_state.current_user, post_text)
|
| 122 |
+
st.success("Post added successfully.")
|
| 123 |
+
st.rerun()
|
| 124 |
+
except Exception as e:
|
| 125 |
+
st.error(f"Error: {e}")
|
| 126 |
+
|
| 127 |
+
# Display all posts
|
| 128 |
posts = client.get_posts()
|
| 129 |
all_posts = []
|
| 130 |
for user_name, user_posts in posts.items():
|
|
|
|
| 153 |
page = st.sidebar.selectbox(
|
| 154 |
"Choose an action",
|
| 155 |
[
|
| 156 |
+
"View All Posts",
|
| 157 |
"Delete Account",
|
| 158 |
"Get Posts for User",
|
| 159 |
"Get Posts for Topic",
|
| 160 |
"Get Trending Topics",
|
|
|
|
| 161 |
],
|
| 162 |
+
index=0,
|
| 163 |
)
|
| 164 |
|
| 165 |
+
if page == "View All Posts":
|
| 166 |
+
get_all_posts()
|
| 167 |
elif page == "Delete Account":
|
| 168 |
delete_own_user()
|
| 169 |
elif page == "Get Posts for User":
|
|
|
|
| 172 |
get_posts_for_topic()
|
| 173 |
elif page == "Get Trending Topics":
|
| 174 |
get_trending_topics()
|
|
|
|
|
|
|
| 175 |
else:
|
| 176 |
page = st.sidebar.selectbox("Choose an action", ["Login", "Register"], index=0)
|
| 177 |
if page == "Login":
|