Update app.py
Browse files
app.py
CHANGED
@@ -1503,6 +1503,37 @@ def show_story():
|
|
1503 |
</div>
|
1504 |
""", unsafe_allow_html=True)
|
1505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1506 |
def show_feedback_section():
|
1507 |
"""Display writing feedback section"""
|
1508 |
if not st.session_state.feedback:
|
@@ -1998,6 +2029,14 @@ def show_main_interface():
|
|
1998 |
def main():
|
1999 |
"""Main application entry point"""
|
2000 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001 |
# Initialize states
|
2002 |
init_session_state()
|
2003 |
init_theme_state()
|
@@ -2010,18 +2049,72 @@ def main():
|
|
2010 |
</div>
|
2011 |
""", unsafe_allow_html=True)
|
2012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013 |
# Show header
|
2014 |
st.markdown("# 📖 JoyStory")
|
2015 |
show_welcome_section()
|
2016 |
show_parent_guide()
|
2017 |
|
2018 |
-
# Sidebar
|
2019 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020 |
show_sidebar()
|
2021 |
|
2022 |
# Session Status Check
|
2023 |
check_session_status()
|
2024 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025 |
# Main content area
|
2026 |
main_container = st.container()
|
2027 |
with main_container:
|
@@ -2038,9 +2131,49 @@ def main():
|
|
2038 |
if st.session_state.story:
|
2039 |
auto_save_progress()
|
2040 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2041 |
except Exception as e:
|
2042 |
handle_application_error(e)
|
2043 |
|
|
|
|
|
|
|
2044 |
def check_session_status():
|
2045 |
"""Check and maintain session status"""
|
2046 |
try:
|
|
|
1503 |
</div>
|
1504 |
""", unsafe_allow_html=True)
|
1505 |
|
1506 |
+
def show_settings_hint():
|
1507 |
+
"""Show floating hint for settings sidebar"""
|
1508 |
+
st.markdown("""
|
1509 |
+
<div style="
|
1510 |
+
position: fixed;
|
1511 |
+
left: 10px;
|
1512 |
+
top: 50%;
|
1513 |
+
transform: translateY(-50%);
|
1514 |
+
background-color: #1e88e5;
|
1515 |
+
color: white;
|
1516 |
+
padding: 10px;
|
1517 |
+
border-radius: 0 8px 8px 0;
|
1518 |
+
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
|
1519 |
+
cursor: pointer;
|
1520 |
+
z-index: 1000;
|
1521 |
+
animation: pulse 2s infinite;
|
1522 |
+
">
|
1523 |
+
<div style="writing-mode: vertical-rl; text-orientation: mixed;">
|
1524 |
+
⚙️ ตั้งค่าระดับความยาก
|
1525 |
+
</div>
|
1526 |
+
</div>
|
1527 |
+
|
1528 |
+
<style>
|
1529 |
+
@keyframes pulse {
|
1530 |
+
0% { transform: translateY(-50%) scale(1); }
|
1531 |
+
50% { transform: translateY(-50%) scale(1.05); }
|
1532 |
+
100% { transform: translateY(-50%) scale(1); }
|
1533 |
+
}
|
1534 |
+
</style>
|
1535 |
+
""", unsafe_allow_html=True)
|
1536 |
+
|
1537 |
def show_feedback_section():
|
1538 |
"""Display writing feedback section"""
|
1539 |
if not st.session_state.feedback:
|
|
|
2029 |
def main():
|
2030 |
"""Main application entry point"""
|
2031 |
try:
|
2032 |
+
# Page config
|
2033 |
+
st.set_page_config(
|
2034 |
+
page_title="JoyStory - Interactive Story Adventure",
|
2035 |
+
page_icon="📖",
|
2036 |
+
layout="wide",
|
2037 |
+
initial_sidebar_state="collapsed"
|
2038 |
+
)
|
2039 |
+
|
2040 |
# Initialize states
|
2041 |
init_session_state()
|
2042 |
init_theme_state()
|
|
|
2049 |
</div>
|
2050 |
""", unsafe_allow_html=True)
|
2051 |
|
2052 |
+
# แสดงแถบเตือนด้านบนเมื่อเริ่มต้นใช้งาน
|
2053 |
+
if 'show_settings_notice' not in st.session_state:
|
2054 |
+
st.session_state.show_settings_notice = True
|
2055 |
+
|
2056 |
+
if st.session_state.show_settings_notice:
|
2057 |
+
st.info("""
|
2058 |
+
💡 **คำแนะนำ:** คลิกที่ ≡ มุมซ้ายบนเพื่อตั้งค่าระดับความยาก (Beginner, Intermediate, Advanced)
|
2059 |
+
และโหลดความก้าวหน้าของคุณ
|
2060 |
+
""")
|
2061 |
+
if st.button("✕ ซ่อนคำแนะนำ"):
|
2062 |
+
st.session_state.show_settings_notice = False
|
2063 |
+
st.rerun()
|
2064 |
+
|
2065 |
# Show header
|
2066 |
st.markdown("# 📖 JoyStory")
|
2067 |
show_welcome_section()
|
2068 |
show_parent_guide()
|
2069 |
|
2070 |
+
# Sidebar with enhanced UI
|
2071 |
with st.sidebar:
|
2072 |
+
st.markdown("""
|
2073 |
+
<div style="text-align: center; padding: 10px; background-color: #f0f7ff;
|
2074 |
+
border-radius: 8px; margin-bottom: 20px;">
|
2075 |
+
<h3 style="color: #1e88e5; margin: 0;">⚙️ การตั้งค่า</h3>
|
2076 |
+
<p style="color: #666; margin: 10px 0 0 0; font-size: 0.9em;">
|
2077 |
+
ปรับแต่งระดับความยากและจัดการความก้าวหน้าของคุณ
|
2078 |
+
</p>
|
2079 |
+
</div>
|
2080 |
+
""", unsafe_allow_html=True)
|
2081 |
show_sidebar()
|
2082 |
|
2083 |
# Session Status Check
|
2084 |
check_session_status()
|
2085 |
|
2086 |
+
# แสดงตัวบ่งชี้ด้านข้าง (ถ้า sidebar ถูกซ่อนอยู่)
|
2087 |
+
if st.session_state.get('initial_load', True):
|
2088 |
+
st.markdown("""
|
2089 |
+
<div style="
|
2090 |
+
position: fixed;
|
2091 |
+
left: 10px;
|
2092 |
+
top: 50%;
|
2093 |
+
transform: translateY(-50%);
|
2094 |
+
background-color: #1e88e5;
|
2095 |
+
color: white;
|
2096 |
+
padding: 10px;
|
2097 |
+
border-radius: 0 8px 8px 0;
|
2098 |
+
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
|
2099 |
+
cursor: pointer;
|
2100 |
+
z-index: 1000;
|
2101 |
+
animation: pulse 2s infinite;
|
2102 |
+
">
|
2103 |
+
<div style="writing-mode: vertical-rl; text-orientation: mixed;">
|
2104 |
+
⚙️ ตั้งค่าระดับความยาก
|
2105 |
+
</div>
|
2106 |
+
</div>
|
2107 |
+
|
2108 |
+
<style>
|
2109 |
+
@keyframes pulse {
|
2110 |
+
0% { transform: translateY(-50%) scale(1); }
|
2111 |
+
50% { transform: translateY(-50%) scale(1.05); }
|
2112 |
+
100% { transform: translateY(-50%) scale(1); }
|
2113 |
+
}
|
2114 |
+
</style>
|
2115 |
+
""", unsafe_allow_html=True)
|
2116 |
+
st.session_state.initial_load = False
|
2117 |
+
|
2118 |
# Main content area
|
2119 |
main_container = st.container()
|
2120 |
with main_container:
|
|
|
2131 |
if st.session_state.story:
|
2132 |
auto_save_progress()
|
2133 |
|
2134 |
+
# Add CSS for sidebar enhancement
|
2135 |
+
st.markdown("""
|
2136 |
+
<style>
|
2137 |
+
/* Highlight sidebar toggle button */
|
2138 |
+
[data-testid="baseButton-header"] {
|
2139 |
+
background-color: #e3f2fd !important;
|
2140 |
+
border-radius: 8px !important;
|
2141 |
+
animation: highlight 2s infinite;
|
2142 |
+
}
|
2143 |
+
|
2144 |
+
@keyframes highlight {
|
2145 |
+
0% { box-shadow: 0 0 0 0 rgba(30,136,229,0.4); }
|
2146 |
+
70% { box-shadow: 0 0 0 10px rgba(30,136,229,0); }
|
2147 |
+
100% { box-shadow: 0 0 0 0 rgba(30,136,229,0); }
|
2148 |
+
}
|
2149 |
+
|
2150 |
+
/* Style sidebar */
|
2151 |
+
.css-1d391kg {
|
2152 |
+
background-color: #fafafa;
|
2153 |
+
border-right: 1px solid #e0e0e0;
|
2154 |
+
}
|
2155 |
+
|
2156 |
+
/* Enhance sidebar buttons */
|
2157 |
+
.stButton > button {
|
2158 |
+
width: 100%;
|
2159 |
+
margin: 5px 0;
|
2160 |
+
border-radius: 8px;
|
2161 |
+
transition: all 0.2s;
|
2162 |
+
}
|
2163 |
+
|
2164 |
+
.stButton > button:hover {
|
2165 |
+
transform: translateY(-2px);
|
2166 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
2167 |
+
}
|
2168 |
+
</style>
|
2169 |
+
""", unsafe_allow_html=True)
|
2170 |
+
|
2171 |
except Exception as e:
|
2172 |
handle_application_error(e)
|
2173 |
|
2174 |
+
if __name__ == "__main__":
|
2175 |
+
main()
|
2176 |
+
|
2177 |
def check_session_status():
|
2178 |
"""Check and maintain session status"""
|
2179 |
try:
|