ui improvements
This commit is contained in:
@@ -40,6 +40,8 @@ if "status_container_key" not in st.session_state:
|
||||
st.session_state.status_container_key = 0
|
||||
if "selected_group_id" not in st.session_state:
|
||||
st.session_state.selected_group_id = None
|
||||
if "announcement_start_time" not in st.session_state:
|
||||
st.session_state.announcement_start_time = None
|
||||
|
||||
|
||||
def show_announcement_status(group_id: int):
|
||||
@@ -65,7 +67,7 @@ def show_announcement_status(group_id: int):
|
||||
with status:
|
||||
# Calculate progress from state value (normalize to 0.0-1.0 range)
|
||||
# Assuming states are ordered from IDLE(0) to COMPLETED(4)
|
||||
max_state_value = 4 # COMPLETED is the maximum state value
|
||||
max_state_value = 1.0 # COMPLETED is the maximum state value
|
||||
progress = min(state["value"] / max_state_value, 1.0)
|
||||
|
||||
# Progress elements
|
||||
@@ -80,21 +82,28 @@ def show_announcement_status(group_id: int):
|
||||
start_tracking_time = time.time()
|
||||
|
||||
# Update loop
|
||||
while state["name"] not in ["COMPLETED", "IDLE"]:
|
||||
while state["name"] not in ["COMPLETED", "IDLE", "ERROR"]:
|
||||
# Check for timeout
|
||||
elapsed_time = time.time() - start_tracking_time
|
||||
if elapsed_time > max_wait_time:
|
||||
st.warning(f"Status tracking timed out after {max_wait_time} seconds")
|
||||
break
|
||||
|
||||
# Only update stage display if state changed
|
||||
# Only update stage display and elapsed time if state changed
|
||||
if state != last_state:
|
||||
stage_col.write(f"**Stage:** {state['name']}")
|
||||
last_state = state
|
||||
|
||||
# Show start time if available
|
||||
start_time = group.get("anouncement_start_time", time.time())
|
||||
time_col.write(f"⏱️ Time elapsed: {time.time() - start_time:.1f}s")
|
||||
# Update elapsed time only on state change
|
||||
if "announcement_start_time" in st.session_state:
|
||||
start_time = st.session_state.announcement_start_time
|
||||
elapsed_seconds = time.time() - start_time
|
||||
time_col.write(f"⏱️ {elapsed_seconds:.1f}s")
|
||||
else:
|
||||
# If no start time is available, use the tracking start time
|
||||
elapsed_seconds = time.time() - start_tracking_time
|
||||
time_col.write(f"⏱️ {elapsed_seconds:.1f}s")
|
||||
|
||||
last_state = state
|
||||
|
||||
# Update progress bar directly from state value
|
||||
progress = min(state["value"] / max_state_value, 1.0)
|
||||
@@ -110,6 +119,18 @@ def show_announcement_status(group_id: int):
|
||||
progress = min(state["value"] / max_state_value, 1.0)
|
||||
progress_bar.progress(progress)
|
||||
|
||||
# Final update to stage display - this ensures we see the COMPLETED state
|
||||
stage_col.write(f"**Stage:** {state['name']}")
|
||||
|
||||
# Final update to elapsed time display
|
||||
if "announcement_start_time" in st.session_state:
|
||||
start_time = st.session_state.announcement_start_time
|
||||
final_elapsed_seconds = time.time() - start_time
|
||||
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
||||
else:
|
||||
final_elapsed_seconds = time.time() - start_tracking_time
|
||||
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
||||
|
||||
# Final state
|
||||
if state["name"] == "COMPLETED":
|
||||
st.success("✅ Announcement completed successfully")
|
||||
@@ -176,6 +197,9 @@ with st.container():
|
||||
# Save the selected group ID for status tracking
|
||||
st.session_state.selected_group_id = selected_group_id
|
||||
|
||||
# Store the start time in session state
|
||||
st.session_state.announcement_start_time = time.time()
|
||||
|
||||
start_announcement(message, selected_group_id)
|
||||
|
||||
# Set flag to show success message
|
||||
@@ -190,6 +214,10 @@ with st.container():
|
||||
except requests.exceptions.RequestException as e:
|
||||
st.error(f"Failed to start announcement: {str(e)}")
|
||||
|
||||
# Show status of any ongoing announcements after the announcement form
|
||||
if st.session_state.show_success_message and st.session_state.selected_group_id is not None:
|
||||
show_announcement_status(st.session_state.selected_group_id)
|
||||
|
||||
# Configuration section in sidebar
|
||||
with st.sidebar:
|
||||
st.header("Configuration")
|
||||
@@ -314,7 +342,3 @@ with st.sidebar:
|
||||
|
||||
# Separator for visual clarity
|
||||
st.markdown("---")
|
||||
|
||||
# Show status of any ongoing announcements
|
||||
if st.session_state.show_success_message and st.session_state.selected_group_id is not None:
|
||||
show_announcement_status(st.session_state.selected_group_id)
|
||||
|
||||
Reference in New Issue
Block a user