File size: 1,625 Bytes
c1f566c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
031f614
c1f566c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71a2c91
 
c1f566c
 
 
 
 
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
import streamlit as st
from data import storiesDb
import constants as C
import utils as U

st.set_page_config(
    page_title="Popular Stories Databse",
    page_icon=C.AI_ICON,
    # menu_items={"About": None}
)

U.applyCommonStyles()
st.markdown(
    """
    <style>

    div[data-testid="stAppViewBlockContainer"] {
        margin-top: -75px;
    }

    </style>
    """,
    unsafe_allow_html=True
)

st.subheader("Choose a popular story")

storyPlaceholder = st.empty()
col1, col2, col3 = storyPlaceholder.columns([1.5, 2.2, 1.5])
col2.image(C.DB_LOADER)
col2.write(
    """
    <div class='blinking code large'>
    Loading from database ...
    </div>
    """,
    unsafe_allow_html=True
)

if "dbStories" not in st.session_state:
    st.session_state.dbStories = storiesDb.getAllStories()

with storyPlaceholder.container(border=False, height=500):
    for idx, story in enumerate(st.session_state.dbStories):
        storyTitle = story['Story Title']
        storyDetails = story['Story Text']
        with st.expander(storyTitle):
            st.markdown(storyDetails)
            if st.button(
                "Select",
                key=f"select_{idx}",
                type="primary",
                use_container_width=True
            ):
                U.pprint(f"Selected story: {storyTitle}")
                st.session_state.isStoryChosen = True
                st.session_state.selectedStoryTitle = storyTitle
                st.session_state.selectedStory = {
                    "title": storyTitle,
                    "text": storyDetails
                }
                st.switch_page("app.py")