From: Claromes Date: Mon, 15 May 2023 22:24:40 +0000 (-0300) Subject: add scroll top X-Git-Url: https://git.claromes.com/?a=commitdiff_plain;h=0167b43918d08c05d201ab1ccc364431907e2b91;p=waybacktweets.git add scroll top --- diff --git a/app.py b/app.py index 7fd04e6..6234102 100644 --- a/app.py +++ b/app.py @@ -43,7 +43,8 @@ hide_streamlit_style = ''' } ''' -# st.markdown(hide_streamlit_style, unsafe_allow_html=True) + +#st.markdown(hide_streamlit_style, unsafe_allow_html=True) if 'current_index' not in st.session_state: st.session_state.current_index = 0 @@ -54,6 +55,15 @@ if 'disabled_next' not in st.session_state: if 'disabled_prev' not in st.session_state: st.session_state.disabled_prev = False +def scroll_into_view(): + js = ''' + + ''' + + st.components.v1.html(js) + def embed(tweet): api = 'https://publish.twitter.com/oembed?url={}'.format(tweet) response = requests.get(api) @@ -167,10 +177,12 @@ if query or handle: prev, _ , next = st.columns([3, 4, 3]) - if prev.button('Previous', disabled=st.session_state.disabled_prev, type='primary', use_container_width=True) and st.session_state.current_index > 0: + if prev.button('Previous', disabled=st.session_state.disabled_prev, type='primary', use_container_width=True): + scroll_into_view() st.session_state.current_index -= tweets_per_page - if next.button('Next', disabled=st.session_state.disabled_next, type='primary', use_container_width=True) and end_index < len(parsed_links): + if next.button('Next', disabled=st.session_state.disabled_next, type='primary', use_container_width=True): + scroll_into_view() st.session_state.current_index += tweets_per_page if st.session_state.current_index >= len(parsed_links):