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
|
st.session_state.status_container_key = 0
|
||||||
if "selected_group_id" not in st.session_state:
|
if "selected_group_id" not in st.session_state:
|
||||||
st.session_state.selected_group_id = None
|
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):
|
def show_announcement_status(group_id: int):
|
||||||
@@ -65,7 +67,7 @@ def show_announcement_status(group_id: int):
|
|||||||
with status:
|
with status:
|
||||||
# Calculate progress from state value (normalize to 0.0-1.0 range)
|
# Calculate progress from state value (normalize to 0.0-1.0 range)
|
||||||
# Assuming states are ordered from IDLE(0) to COMPLETED(4)
|
# 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 = min(state["value"] / max_state_value, 1.0)
|
||||||
|
|
||||||
# Progress elements
|
# Progress elements
|
||||||
@@ -80,21 +82,28 @@ def show_announcement_status(group_id: int):
|
|||||||
start_tracking_time = time.time()
|
start_tracking_time = time.time()
|
||||||
|
|
||||||
# Update loop
|
# Update loop
|
||||||
while state["name"] not in ["COMPLETED", "IDLE"]:
|
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
|
||||||
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
|
||||||
|
|
||||||
# Only update stage display if state changed
|
# Only update stage display and elapsed time if state changed
|
||||||
if state != last_state:
|
if state != last_state:
|
||||||
stage_col.write(f"**Stage:** {state['name']}")
|
stage_col.write(f"**Stage:** {state['name']}")
|
||||||
last_state = state
|
|
||||||
|
|
||||||
# Show start time if available
|
# Update elapsed time only on state change
|
||||||
start_time = group.get("anouncement_start_time", time.time())
|
if "announcement_start_time" in st.session_state:
|
||||||
time_col.write(f"⏱️ Time elapsed: {time.time() - start_time:.1f}s")
|
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
|
# 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)
|
||||||
@@ -110,6 +119,18 @@ def show_announcement_status(group_id: int):
|
|||||||
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
|
||||||
|
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
|
# Final state
|
||||||
if state["name"] == "COMPLETED":
|
if state["name"] == "COMPLETED":
|
||||||
st.success("✅ Announcement completed successfully")
|
st.success("✅ Announcement completed successfully")
|
||||||
@@ -176,6 +197,9 @@ with st.container():
|
|||||||
# Save the selected group ID for status tracking
|
# Save the selected group ID for status tracking
|
||||||
st.session_state.selected_group_id = selected_group_id
|
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)
|
start_announcement(message, selected_group_id)
|
||||||
|
|
||||||
# Set flag to show success message
|
# Set flag to show success message
|
||||||
@@ -190,6 +214,10 @@ with st.container():
|
|||||||
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)}")
|
||||||
|
|
||||||
|
# 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
|
# Configuration section in sidebar
|
||||||
with st.sidebar:
|
with st.sidebar:
|
||||||
st.header("Configuration")
|
st.header("Configuration")
|
||||||
@@ -314,7 +342,3 @@ with st.sidebar:
|
|||||||
|
|
||||||
# Separator for visual clarity
|
# Separator for visual clarity
|
||||||
st.markdown("---")
|
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