From 86c88b1ac0c686b58e2a02509932b9fd8af495a4 Mon Sep 17 00:00:00 2001 From: Merlin Unterfinger Date: Mon, 7 Oct 2024 17:14:15 +0200 Subject: [PATCH] enh: conditionally show upload reset or example --- rssched/app/upload.py | 51 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/rssched/app/upload.py b/rssched/app/upload.py index b8e8620..3303ad0 100644 --- a/rssched/app/upload.py +++ b/rssched/app/upload.py @@ -70,30 +70,41 @@ def handle_file_upload() -> Optional[Tuple[BytesIO, BytesIO]]: """ ) -st.subheader("Upload Data") - # Initialize session state to store file uploads if "request_file" not in st.session_state: st.session_state.request_file = None if "response_file" not in st.session_state: st.session_state.response_file = None -# Handle file uploads -uploaded_files = handle_file_upload() - -if uploaded_files: - request_file, response_file = uploaded_files - set_file_in_session_state(request_file, response_file) +# Check if files have been uploaded +files_uploaded = ( + st.session_state.request_file is not None + and st.session_state.response_file is not None +) -# Reset button to clear the uploaded files and session state -if st.button("Reset"): - st.session_state.request_file = None - st.session_state.response_file = None - st.session_state.request_data = None - st.session_state.response_data = None - st.rerun() - -# Load example files when the "Load Example" button is clicked -if st.button("Load Example"): - example_request_file, example_response_file = load_example_files() - set_file_in_session_state(example_request_file, example_response_file) +# Display file uploaders and "Load Example" button only if no files have been uploaded +if not files_uploaded: + st.subheader("Upload Data") + uploaded_files = handle_file_upload() + if uploaded_files: + request_file, response_file = uploaded_files + set_file_in_session_state(request_file, response_file) + st.rerun() + + if st.button("Load Example"): + example_request_file, example_response_file = load_example_files() + set_file_in_session_state(example_request_file, example_response_file) + st.rerun() + + +# Show the reset button only if files have been uploaded +if files_uploaded: + st.subheader("Uploaded Data") + st.write(f"**Request File:** {st.session_state.request_file.name}") + st.write(f"**Response File:** {st.session_state.response_file.name}") + if st.button("Reset"): + st.session_state.request_file = None + st.session_state.response_file = None + st.session_state.request_data = None + st.session_state.response_data = None + st.rerun()