James McCool
commited on
Commit
Β·
dd71678
1
Parent(s):
a19edd8
Enhance pagination logic and session state management in app.py
Browse files- Improved navigation controls by ensuring the current page is correctly initialized and updated, preventing potential errors when accessing pagination.
- Added checks to maintain session state integrity, ensuring that 'current_page' is set appropriately and relevant session data is cleared upon navigation.
- Enhanced user experience by providing clearer feedback on the current page being displayed.
app.py
CHANGED
@@ -197,16 +197,21 @@ with tab2:
|
|
197 |
pagination_cols = st.columns([4, 1, 1, 1, 4])
|
198 |
with pagination_cols[1]:
|
199 |
if st.button("β Previous", disabled=st.session_state.current_page == 0):
|
200 |
-
st.session_state
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
204 |
|
205 |
with pagination_cols[2]:
|
206 |
st.markdown(f"**Page {st.session_state.current_page + 1} of {total_pages}**", unsafe_allow_html=True)
|
|
|
207 |
with pagination_cols[3]:
|
208 |
if st.button("Next β", disabled=st.session_state.current_page == total_pages - 1):
|
209 |
-
st.session_state
|
|
|
|
|
|
|
210 |
if 'player_frame' in st.session_state:
|
211 |
del st.session_state['player_frame']
|
212 |
del st.session_state['stack_frame']
|
|
|
197 |
pagination_cols = st.columns([4, 1, 1, 1, 4])
|
198 |
with pagination_cols[1]:
|
199 |
if st.button("β Previous", disabled=st.session_state.current_page == 0):
|
200 |
+
if st.session_state['current_page'] > 0:
|
201 |
+
st.session_state.current_page -= 1
|
202 |
+
if 'player_frame' in st.session_state:
|
203 |
+
del st.session_state['player_frame']
|
204 |
+
del st.session_state['stack_frame']
|
205 |
|
206 |
with pagination_cols[2]:
|
207 |
st.markdown(f"**Page {st.session_state.current_page + 1} of {total_pages}**", unsafe_allow_html=True)
|
208 |
+
|
209 |
with pagination_cols[3]:
|
210 |
if st.button("Next β", disabled=st.session_state.current_page == total_pages - 1):
|
211 |
+
if 'current_page' not in st.session_state:
|
212 |
+
st.session_state.current_page = 1
|
213 |
+
else:
|
214 |
+
st.session_state.current_page += 1
|
215 |
if 'player_frame' in st.session_state:
|
216 |
del st.session_state['player_frame']
|
217 |
del st.session_state['stack_frame']
|