From: Claromes Date: Fri, 19 May 2023 21:29:18 +0000 (-0300) Subject: fix scroll X-Git-Url: https://git.claromes.com/?a=commitdiff_plain;h=1e1269b0d1b3f05016b8273be8ef944e84cb0455;p=waybacktweets.git fix scroll --- diff --git a/README.md b/README.md index 07c736e..caea2f9 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ Streamlit will be served at http://localhost:8501 - [ ] "web.archive.org took too long to respond." - [x] `only_deleted` checkbox selected for handles without deleted tweets - - [ ] Add message if handle has no deleted tweets + - [ ] Check and add message if handle has no deleted tweets in the range - [x] Pagination: set session variable on first click -- [ ] Pagination: scroll to top +- [x] Pagination: scroll to top ## Roadmap diff --git a/app.py b/app.py index 38142c9..6e892af 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ import datetime import streamlit as st import streamlit.components.v1 as components -__version__ = '0.1.0' +__version__ = '0.1.1' st.set_page_config( page_title='Wayback Tweets', @@ -67,6 +67,19 @@ if 'next_button' not in st.session_state: if 'prev_button' not in st.session_state: st.session_state.prev_button = False +if 'update_component' not in st.session_state: + st.session_state.update_component = 0 + +def scroll_into_view(): + js = ''' + + '''.format(st.session_state.update_component) + + components.html(js, width=0, height=0) + def embed(tweet): api = 'https://publish.twitter.com/oembed?url={}'.format(tweet) response = requests.get(api) @@ -112,7 +125,7 @@ def attr(i): '''.format(i+1, link, mimetype[i], datetime.datetime.strptime(timestamp[i], "%Y%m%d%H%M%S"), tweet_links[i])) st.title('Wayback Tweets [![GitHub release (latest by date)](https://img.shields.io/github/v/release/claromes/waybacktweets)](https://github.com/claromes/waybacktweets/releases)', anchor=False) -st.write('Archived tweets on Wayback Machine') +st.write('Search archived tweets on Wayback Machine in a easy way') handle = st.text_input('username', placeholder='username', label_visibility='collapsed') query = st.button('Query', type='primary', use_container_width=True) @@ -146,9 +159,17 @@ if query or handle: def prev_page(): st.session_state.current_index -= tweets_per_page + #scroll to top config + st.session_state.update_component += 1 + scroll_into_view() + def next_page(): st.session_state.current_index += tweets_per_page + #scroll to top config + st.session_state.update_component += 1 + scroll_into_view() + start_index = st.session_state.current_index end_index = min(len(parsed_links), start_index + tweets_per_page) @@ -161,10 +182,10 @@ if query or handle: if tweet == None: st.error('Tweet has been deleted.') - st.markdown(''.format(link), unsafe_allow_html=True) + components.iframe(src=link, width=700, height=700) st.divider() else: - components.html(tweet,width=700, height=700, scrolling=True) + components.html(tweet, width=700, height=700, scrolling=True) st.divider() progress.write('{}/{} URLs have been captured'.format(i + 1, len(parsed_links))) @@ -175,7 +196,7 @@ if query or handle: attr(i) st.error('Tweet has been deleted.') - st.markdown(''.format(link), unsafe_allow_html=True) + components.iframe(src=link, width=700, height=700) st.divider() progress.write('{}/{}-{} URLs have been captured'.format(return_none_count, start_index, end_index))