ui improvements
This commit is contained in:
@@ -86,6 +86,9 @@ def show_announcement_status(group_id: int):
|
|||||||
while state_name not in ["COMPLETED", "IDLE", "ERROR"]:
|
while state_name not in ["COMPLETED", "IDLE", "ERROR"]:
|
||||||
# Check for timeout
|
# Check for timeout
|
||||||
elapsed_time = time.time() - start_tracking_time
|
elapsed_time = time.time() - start_tracking_time
|
||||||
|
# Refresh state
|
||||||
|
state_name, state_value = get_group_state(group_id)
|
||||||
|
|
||||||
if elapsed_time > max_wait_time:
|
if elapsed_time > max_wait_time:
|
||||||
st.warning(f"Status tracking timed out after {max_wait_time} seconds")
|
st.warning(f"Status tracking timed out after {max_wait_time} seconds")
|
||||||
break
|
break
|
||||||
@@ -110,50 +113,58 @@ def show_announcement_status(group_id: int):
|
|||||||
# Update progress bar directly from state value
|
# Update progress bar directly from state value
|
||||||
progress = min(state_value / max_state_value, 1.0)
|
progress = min(state_value / max_state_value, 1.0)
|
||||||
progress_bar.progress(progress)
|
progress_bar.progress(progress)
|
||||||
|
|
||||||
# Add a small delay between requests to avoid hammering the API
|
# Add a small delay between requests to avoid hammering the API
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
# Refresh state
|
|
||||||
state_name, state_value = get_group_state(group_id)
|
|
||||||
|
|
||||||
# Final update to progress bar
|
# Final update to progress bar
|
||||||
progress = min(state_value / max_state_value, 1.0)
|
progress = min(state_value / max_state_value, 1.0)
|
||||||
progress_bar.progress(progress)
|
progress_bar.progress(progress)
|
||||||
|
|
||||||
# Final update to stage display - this ensures we see the COMPLETED state
|
# Final update to stage display and time only if the state isn't already shown
|
||||||
stage_col.write(f"**Stage:** {state_name}")
|
if last_state is None or last_state[0] != state_name:
|
||||||
|
stage_col.write(f"**Stage:** {state_name}")
|
||||||
# Final update to elapsed time display
|
|
||||||
if "announcement_start_time" in st.session_state:
|
# Only update time when we update the stage
|
||||||
start_time = st.session_state.announcement_start_time
|
if "announcement_start_time" in st.session_state:
|
||||||
final_elapsed_seconds = time.time() - start_time
|
start_time = st.session_state.announcement_start_time
|
||||||
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
final_elapsed_seconds = time.time() - start_time
|
||||||
else:
|
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
||||||
final_elapsed_seconds = time.time() - start_tracking_time
|
else:
|
||||||
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
final_elapsed_seconds = time.time() - start_tracking_time
|
||||||
|
time_col.write(f"⏱️ {final_elapsed_seconds:.1f}s")
|
||||||
|
|
||||||
# Final state
|
# Final state
|
||||||
if state_name == "COMPLETED":
|
if state_name == "COMPLETED":
|
||||||
st.success("✅ Announcement completed successfully")
|
# Only display success message if we haven't shown one for this announcement yet
|
||||||
|
if st.session_state.show_success_message:
|
||||||
# Display group information
|
st.success("✅ Announcement completed successfully")
|
||||||
st.write(f"📢 Announcement made to group {group.name}")
|
|
||||||
|
# Display group information
|
||||||
# Display endpoints if available
|
st.write(f"📢 Announcement made to group {group.name}")
|
||||||
endpoints = group.endpoints
|
|
||||||
if endpoints:
|
# Display endpoints if available
|
||||||
endpoint_names = [ep.name for ep in endpoints]
|
endpoints = group.endpoints
|
||||||
st.write(f"📡 Endpoints: {', '.join(endpoint_names)}")
|
if endpoints:
|
||||||
|
endpoint_names = [ep.name for ep in endpoints]
|
||||||
# Display languages if available
|
st.write(f"📡 Endpoints: {', '.join(endpoint_names)}")
|
||||||
languages = group.languages
|
|
||||||
if languages:
|
# Display languages if available
|
||||||
st.write(f"🌐 Languages: {', '.join(languages)}")
|
languages = group.languages
|
||||||
|
if languages:
|
||||||
# Clear the success message when announcement completes
|
st.write(f"🌐 Languages: {', '.join(languages)}")
|
||||||
st.session_state.show_success_message = False
|
|
||||||
|
# Clear the success message to prevent showing the status again
|
||||||
|
st.session_state.show_success_message = False # Clear success message after announcement completion
|
||||||
|
|
||||||
|
if state_name == "ERROR":
|
||||||
|
st.error("❌ Announcement encountered an error")
|
||||||
|
st.session_state.show_success_message = False # Clear success message on error
|
||||||
|
|
||||||
|
# Increment announcement ID to ensure a fresh status container
|
||||||
|
st.session_state.announcement_id += 1
|
||||||
|
st.session_state.status_container_key = st.session_state.announcement_id
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
st.error(f"Failed to get announcement status: {str(e)}")
|
st.error(f"Failed to get announcement status: {str(e)}")
|
||||||
|
|
||||||
@@ -203,14 +214,12 @@ with st.container():
|
|||||||
# Update session state with the current message
|
# Update session state with the current message
|
||||||
st.session_state.announcement_text = message
|
st.session_state.announcement_text = message
|
||||||
|
|
||||||
start_announcement(message, selected_group_id)
|
|
||||||
|
|
||||||
# Set flag to show success message
|
# Set flag to show success message
|
||||||
st.session_state.show_success_message = True
|
st.session_state.show_success_message = True
|
||||||
|
|
||||||
# Increment announcement ID to ensure a fresh status container
|
# Start the announcement
|
||||||
st.session_state.announcement_id += 1
|
start_announcement(message, selected_group_id)
|
||||||
st.session_state.status_container_key = st.session_state.announcement_id
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
st.error(f"Failed to start announcement: {str(e)}")
|
st.error(f"Failed to start announcement: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user