fix: SSE 实时更新同步状态指示器

sync-status 区域未包含在 SSE OOB swap 中,导致页面加载后
状态永远不会更新。新增 SyncStatusPartial 模板并加入 SSE
payload,使 dirty count 归零时 UI 能实时切换。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
grabbit 2026-02-19 17:30:08 +08:00
parent faf9d80824
commit d5b83a0075
2 changed files with 27 additions and 0 deletions

View File

@ -119,6 +119,10 @@ fn render_sse_payload(
webdav_running: status.webdav_running,
};
let sync_status = SyncStatusPartial {
all_synced: status.all_synced,
};
let mut html = String::new();
// Primary target: dashboard stats
if let Ok(s) = stats.render() {
@ -132,6 +136,10 @@ fn render_sse_payload(
if let Ok(s) = badges.render() {
html.push_str(&s);
}
// OOB: sync status indicator
if let Ok(s) = sync_status.render() {
html.push_str(&s);
}
html
}
@ -205,3 +213,9 @@ struct ProtocolBadgesPartial {
nfs_exported: bool,
webdav_running: bool,
}
#[derive(Template)]
#[template(path = "web/partials/sync_status.html")]
struct SyncStatusPartial {
all_synced: bool,
}

View File

@ -0,0 +1,13 @@
{% if all_synced %}
<div class="sync-indicator sync-ok" id="sync-status" hx-swap-oob="outerHTML:#sync-status">
<span class="sync-icon"></span>
<span class="sync-text">已全部同步 — 可以断网</span>
<span class="sync-sub">All synced — safe to disconnect</span>
</div>
{% else %}
<div class="sync-indicator sync-pending" id="sync-status" hx-swap-oob="outerHTML:#sync-status">
<span class="sync-icon"></span>
<span class="sync-text">同步进行中 — 请勿断网</span>
<span class="sync-sub">Sync in progress — do not disconnect</span>
</div>
{% endif %}