Skip to content

Commit 9a6ef61

Browse files
Merge pull request #35 from merendamattia/issues_solver
Fix scroll behavior after portfolio analysis completion
2 parents cec1918 + 1d30e36 commit 9a6ef61

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

app.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import plotly.graph_objects as go
1717
import requests
1818
import streamlit as st
19+
import streamlit.components.v1 as components
1920
from dotenv import load_dotenv
2021

2122
from src.clients import list_providers
@@ -291,6 +292,31 @@ def initialize_financial_advisor(
291292
raise
292293

293294

295+
def _scroll_to_bottom():
296+
"""
297+
Force scroll to bottom by targeting the specific Streamlit main container.
298+
"""
299+
js = """
300+
<script>
301+
function forceScroll() {
302+
var scrollable_div = window.parent.document.querySelector('section.main') ||
303+
window.parent.document.querySelector('.main') ||
304+
window.parent.document.querySelector('[data-testid="stMain"]');
305+
306+
if (scrollable_div) {
307+
scrollable_div.scrollTop = scrollable_div.scrollHeight;
308+
}
309+
}
310+
311+
setTimeout(forceScroll, 100);
312+
setTimeout(forceScroll, 500);
313+
setTimeout(forceScroll, 1000);
314+
setTimeout(forceScroll, 2000);
315+
</script>
316+
"""
317+
components.html(js, height=0, width=0)
318+
319+
294320
def stream_text(text: str, chunk_size: int = 20):
295321
"""
296322
Stream text with a typing effect by displaying chunks progressively.
@@ -1824,6 +1850,11 @@ def main():
18241850
with st.chat_message(message["role"]):
18251851
st.markdown(message["content"])
18261852

1853+
prompt = st.chat_input(
1854+
"Assessment completed. See the results above.",
1855+
disabled=st.session_state.conversation_completed,
1856+
)
1857+
18271858
# Show message if conversation is completed
18281859
if st.session_state.conversation_completed:
18291860
if not st.session_state.generated_portfolio:
@@ -1912,11 +1943,13 @@ def main():
19121943
"- Click 'Clear Conversation' to start a new assessment or 'Change Provider' to start over"
19131944
)
19141945

1946+
_scroll_to_bottom()
1947+
19151948
else:
19161949
logger.debug("No financial profile available to display")
19171950
else:
1918-
# User input - only show if conversation is not completed
1919-
if prompt := st.chat_input("Ask me about your finances..."):
1951+
# Handle user input ONLY if there is a prompt (i.e., not disabled)
1952+
if prompt:
19201953
logger.debug("User input received: %s", prompt[:100])
19211954

19221955
# Display user message

0 commit comments

Comments
 (0)