From 4b6f2929cbd7b752fc4afaa905a38ed0021d2ac6 Mon Sep 17 00:00:00 2001 From: Claromes Date: Wed, 17 May 2023 14:07:14 -0300 Subject: [PATCH] reset query and handle --- app.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 6234102..81d3a67 100644 --- a/app.py +++ b/app.py @@ -49,6 +49,12 @@ hide_streamlit_style = ''' if 'current_index' not in st.session_state: st.session_state.current_index = 0 +if 'current_query' not in st.session_state: + st.session_state.current_query = '' + +if 'current_handle' not in st.session_state: + st.session_state.current_handle = '' + if 'disabled_next' not in st.session_state: st.session_state.disabled_next = False @@ -115,7 +121,15 @@ st.write('Archived tweets on Wayback Machine') handle = st.text_input('username', placeholder='username', label_visibility='collapsed') query = st.button('Query', type='primary', use_container_width=True) + + if query or handle: + if handle != st.session_state.current_handle: + st.session_state.current_index = 0 + + if query != st.session_state.current_query: + st.session_state.current_index = 0 + with st.spinner(''): progress = st.empty() links = query_api(handle) @@ -129,6 +143,9 @@ if query or handle: if links: st.divider() + st.session_state.current_handle = handle + st.session_state.current_query = query + return_none_count = 0 tweets_per_page = 2 @@ -185,8 +202,8 @@ if query or handle: scroll_into_view() st.session_state.current_index += tweets_per_page - if st.session_state.current_index >= len(parsed_links): - st.session_state.current_index = 0 + # if st.session_state.current_index >= len(parsed_links): + # st.session_state.current_index = 0 if not links: st.error('Unable to query the Wayback Machine API.') -- 2.34.1