From 4ededdc52f48a61fc6ef7c39553491e675e3e8a7 Mon Sep 17 00:00:00 2001 From: Claromes Date: Mon, 15 May 2023 00:17:45 -0300 Subject: [PATCH] fix btn disabled, add pagination in footer --- README.md | 5 +++-- app.py | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4743a96..e72c9fe 100644 --- 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 6939d49..7fd04e6 100644 --- 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 -- 2.34.1