Add HTML5 authoring SSE updates
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 02:41:02 +03:00
parent de7248db9e
commit fb66cfba6f
3 changed files with 17 additions and 3 deletions
+10 -3
View File
@@ -206,7 +206,13 @@ def render_html5_editor(
tree_nodes = objects[:120] or modules[:120]
selected_module = modules[0] if modules else None
content = f"""
<main class="workspace" data-html5-page="editor" data-project-id="{escape(project_id)}">
<main
class="workspace"
data-html5-page="editor"
data-project-id="{escape(project_id)}"
hx-ext="sse"
sse-connect="/html5/projects/{quote(project_id)}/events"
>
{_topbar(project_id, project_nav)}
<section class="layout">
<aside class="panel tree" data-html5-tree>
@@ -259,7 +265,7 @@ def render_html5_editor(
{render_html5_authoring_changes(project_id, None)}
</aside>
</section>
<footer class="status" data-html5-status hx-ext="sse" sse-connect="/html5/projects/{quote(project_id)}/events" sse-swap="status">
<footer class="status" data-html5-status sse-swap="status">
{render_html5_status(project_id, snapshot)}
</footer>
</main>
@@ -651,6 +657,7 @@ def render_html5_authoring_changes(project_id: str, changes: Iterable[object] |
data-html5-authoring-changes
hx-get="/html5/projects/{quote(project_id)}/authoring/changes"
hx-trigger="load"
sse-swap="authoring-changes"
hx-swap="outerHTML"
>
<div class="panel-title">Authoring</div>
@@ -667,7 +674,7 @@ def render_html5_authoring_changes(project_id: str, changes: Iterable[object] |
class="authoring-panel"
data-html5-authoring-changes
hx-get="/html5/projects/{quote(project_id)}/authoring/changes"
hx-trigger="every 15s"
sse-swap="authoring-changes"
hx-swap="outerHTML"
>
<div class="panel-title">Authoring · {len(change_list)}</div>
@@ -1702,6 +1702,10 @@ async def html5_project_events(project_id: str, once: bool = False) -> Streaming
except HTTPException as error:
fragment = f'<span>project: {project_id}</span><span>error: {error.detail}</span>'
yield _html5_sse_event("status", fragment)
yield _html5_sse_event(
"authoring-changes",
render_html5_authoring_changes(project_id, _authoring_change_summaries(project_id)),
)
if once:
break
time.sleep(5)
+3
View File
@@ -125,6 +125,7 @@ def test_html5_server_rendered_project_editor(tmp_path: Path):
assert f'hx-post="/html5/projects/{project_id}/authoring/metadata-object-preview"' in editor.text
assert "data-html5-authoring-changes" in editor.text
assert f'hx-get="/html5/projects/{project_id}/authoring/changes"' in editor.text
assert 'sse-swap="authoring-changes"' in editor.text
assert 'hx-get="/html5/projects/' in editor.text
assert 'hx-target="[data-html5-symbol-results]"' in editor.text
assert 'hx-target="[data-html5-symbol-detail]"' in editor.text
@@ -145,6 +146,8 @@ def test_html5_server_rendered_project_editor(tmp_path: Path):
with client.stream("GET", f"/html5/projects/{project_id}/events?once=1") as events:
first_chunk = next(events.iter_text())
assert "event: status" in first_chunk
assert "event: authoring-changes" in first_chunk
assert "data-html5-authoring-changes" in first_chunk
assert "data:" in first_chunk
assert project_id in first_chunk