refactor: Improve directory processing UI with session state and rerun

This commit is contained in:
Bobby Abellana (aider) 2025-02-11 09:58:00 -08:00
parent 79b2bb0835
commit 6b5c851a00

View File

@ -214,22 +214,24 @@ if uploaded_files:
with col1:
source_dir = st.text_input("Source Directory Path",
help="Enter the full path to the directory containing files to process")
help="Enter the full path to the directory containing files to process",
value=st.session_state.get('source_dir', ''))
source_browse = st.button("Browse Source Directory")
if source_browse:
path = get_directory_path("Select Source Directory")
if path:
source_dir = path
st.session_state['source_dir'] = path # Persist the selection
st.session_state['source_dir'] = path
st.experimental_rerun()
dest_dir = st.text_input("Destination Directory Path",
help="Enter the full path where processed files will be saved")
help="Enter the full path where processed files will be saved",
value=st.session_state.get('dest_dir', ''))
dest_browse = st.button("Browse Destination Directory")
if dest_browse:
path = get_directory_path("Select Destination Directory")
if path:
dest_dir = path
st.session_state['dest_dir'] = path # Persist the selection
st.session_state['dest_dir'] = path
st.experimental_rerun()
with col2:
if file_type == "Excel":
@ -241,7 +243,8 @@ if uploaded_files:
passwords = []
if password_option == "Password File":
password_path = st.text_input("Password File Path",
help="Enter the full path to the text file containing passwords")
help="Enter the full path to the text file containing passwords",
value=st.session_state.get('password_path', ''))
password_browse = st.button("Browse Password File")
if password_browse:
try:
@ -254,8 +257,8 @@ if uploaded_files:
filetypes=[("Text Files", "*.txt")]
)
if file_path:
password_path = file_path
st.session_state['password_path'] = file_path
st.experimental_rerun()
except Exception as e:
st.error(f"Error opening file dialog: {str(e)}")