fix btn disabled, add pagination in footer
authorClaromes <claromes@hey.com>
Mon, 15 May 2023 03:17:45 +0000 (00:17 -0300)
committerClaromes <claromes@hey.com>
Mon, 15 May 2023 03:17:45 +0000 (00:17 -0300)
README.md
app.py

index 4743a96ae607d1394de9009ddb771a4be62934b3..e72c9fe39252bf92ec2bc3a2260244d446a9a462 100644 (file)
--- a/README.md
+++ b/README.md
@@ -33,8 +33,9 @@ Streamlit will be served at http://localhost:8501
 ## Roadmap
 
 - [ ] Pagination
-    - [ ] Footer
-    - [ ] Disabled/ Empty
+    - [x] Footer
+    - [x] Disabled/ Empty
+    - [ ] Double click
 - [ ] Feedbacks
 - [ ] Prevent duplicate URLs
 - [ ] Grid
diff --git a/app.py b/app.py
index 6939d49dccc1d0bd8bdd22cccf730bc34d214826..7fd04e6f44cbf79e502a2bc6082f81a46eefdca6 100644 (file)
--- a/app.py
+++ b/app.py
@@ -45,6 +45,15 @@ hide_streamlit_style = '''
 '''
 # st.markdown(hide_streamlit_style, unsafe_allow_html=True)
 
+if 'current_index' not in st.session_state:
+    st.session_state.current_index = 0
+
+if 'disabled_next' not in st.session_state:
+    st.session_state.disabled_next = False
+
+if 'disabled_prev' not in st.session_state:
+    st.session_state.disabled_prev = False
+
 def embed(tweet):
     api = 'https://publish.twitter.com/oembed?url={}'.format(tweet)
     response = requests.get(api)
@@ -113,17 +122,6 @@ if query or handle:
             return_none_count = 0
             tweets_per_page = 2
 
-            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', use_container_width=True) and st.session_state.current_index > 0:
-                st.session_state.current_index -= tweets_per_page
-
-            if next.button('Next', use_container_width=True) and st.session_state.current_index < len(parsed_links):
-                st.session_state.current_index += tweets_per_page
-
             start_index = st.session_state.current_index
             end_index = min(len(parsed_links), start_index + tweets_per_page)
 
@@ -155,6 +153,26 @@ if query or handle:
 
                         progress.write('{}/{}-{} URLs have been captured'.format(return_none_count, start_index, end_index))
 
+                if start_index == 0:
+                    st.session_state.disabled_prev = True
+                else:
+                    st.session_state.disabled_prev = False
+
+                if i + 1 == len(parsed_links):
+                    st.session_state.disabled_next = True
+                else:
+                    st.session_state.disabled_next = False
+
+            print(start_index, end_index)
+
+            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:
+                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):
+                st.session_state.current_index += tweets_per_page
+
             if st.session_state.current_index >= len(parsed_links):
                 st.session_state.current_index = 0