pagination
authorClaromes <claromes@hey.com>
Sat, 13 May 2023 04:54:20 +0000 (01:54 -0300)
committerClaromes <claromes@hey.com>
Sat, 13 May 2023 04:54:20 +0000 (01:54 -0300)
app.py

diff --git a/app.py b/app.py
index bb7603bcca59fb3b8d26b8ceea59ec6c026f3475..29e7b965681d42a1d9d03a72f26355f9e7899f23 100644 (file)
--- a/app.py
+++ b/app.py
@@ -93,7 +93,7 @@ st.title('Wayback Tweets [![Fork me on GitHub](https://img.shields.io/badge/-For
 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, key='init')
+query = st.button('Query', type='primary', use_container_width=True)
 
 if query or handle:
     with st.spinner(''):
@@ -111,8 +111,23 @@ if query or handle:
 
             return_none_count = 0
 
-            for i, link in enumerate(parsed_links):
-                tweet = embed('{}'.format(tweet_links[i]))
+            if 'current_index' not in st.session_state:
+                st.session_state.current_index = 0
+
+            previous, _ , next = st.columns([3, 4, 3])
+
+            if previous.button('Previous', type='primary', use_container_width=True):
+                st.session_state.current_index -= 50
+
+            if next.button('Next', type='primary', use_container_width=True):
+                st.session_state.current_index += 50
+
+            start_index = st.session_state.current_index
+            end_index = min(len(parsed_links), start_index + 50)
+
+            for i in range(start_index, end_index):
+                link = parsed_links[i]
+                tweet = embed(tweet_links[i])
 
                 if not only_deleted:
                     attr(i)
@@ -138,5 +153,8 @@ if query or handle:
 
                         progress.write('{}/{} URLs have been captured'.format(return_none_count, len(parsed_links)))
 
+            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.')