-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhome.py
64 lines (46 loc) · 2.29 KB
/
home.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
from firebase_admin import firestore
def app():
if 'db' not in st.session_state:
st.session_state.db = ''
db=firestore.client()
st.session_state.db=db
# st.title(' :violet[Pondering] :sunglasses:')
ph = ''
if st.session_state.username=='':
ph = 'Login to be able to post!!'
else:
ph='Post your thought'
post=st.text_area(label=' :orange[+ New Post]',placeholder=ph,height=None, max_chars=500)
if st.button('Post',use_container_width=20):
if post!='':
info = db.collection('Posts').document(st.session_state.username).get()
if info.exists:
info = info.to_dict()
if 'Content' in info.keys():
pos=db.collection('Posts').document(st.session_state.username)
pos.update({u'Content': firestore.ArrayUnion([u'{}'.format(post)])})
# st.write('Post uploaded!!')
else:
data={"Content":[post],'Username':st.session_state.username}
db.collection('Posts').document(st.session_state.username).set(data)
else:
data={"Content":[post],'Username':st.session_state.username}
db.collection('Posts').document(st.session_state.username).set(data)
st.success('Post uploaded!!')
st.header(' :violet[Latest Posts] ')
docs = db.collection('Posts').get()
for doc in docs:
d=doc.to_dict()
try:
st.markdown("""
<style>
.stTextArea [data-baseweb=base-input] [disabled=""]{
# background-color: #e3d8c8;
-webkit-text-fill-color: white;
}
</style>
""",unsafe_allow_html=True)
st.text_area(label=':green[Posted by:] '+':orange[{}]'.format(d['Username']), value=d['Content'][-1], height=20, disabled=True)
# st.text_area(label=':green[Posted by:] '+':orange[{}]'.format(d['Username']),value=d['Content'][-1],height=20)
except: pass