From f4b4cf3db7195a9d8d6428aeadf7407ee5b21e75 Mon Sep 17 00:00:00 2001 From: adlee-was-taken Date: Sun, 31 May 2026 21:54:42 -0400 Subject: [PATCH] =?UTF-8?q?refactor(ext):=20simplify=20Phase=206=20?= =?UTF-8?q?=E2=80=94=20alias=20VaultStatus=20+=20reuse=20listItems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two simplify-pass cleanups: - vault-status.ts: VaultStatus is now an alias of GetVaultStatusResponse['data'] instead of a re-declared 4-field interface, so the renderer's input shape is single-sourced from the message contract and can't drift from the SW handler. - service-worker/vault.ts: handleGetVaultStatus counts active items via the existing listItems() helper rather than re-implementing the trashed_at filter. Co-Authored-By: Claude Opus 4.8 --- extension/src/service-worker/vault.ts | 4 +--- extension/src/vault/vault-status.ts | 15 ++++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/extension/src/service-worker/vault.ts b/extension/src/service-worker/vault.ts index b189e18..ad91ad3 100644 --- a/extension/src/service-worker/vault.ts +++ b/extension/src/service-worker/vault.ts @@ -566,9 +566,7 @@ export function handleGetVaultStatus( }, ): GetVaultStatusResponse | { ok: false; error: string } { if (!state.gitHost) return { ok: false, error: 'vault_locked' }; - const pendingItems = state.manifest - ? Object.values(state.manifest.items).filter((e) => e.trashed_at === undefined).length - : 0; + const pendingItems = state.manifest ? listItems(state.manifest).length : 0; return { ok: true, data: { diff --git a/extension/src/vault/vault-status.ts b/extension/src/vault/vault-status.ts index b55132f..d68a1b9 100644 --- a/extension/src/vault/vault-status.ts +++ b/extension/src/vault/vault-status.ts @@ -5,16 +5,13 @@ import { GLYPH_PENDING, } from '../shared/glyphs'; import { relativeTime } from '../shared/relative-time'; +import type { GetVaultStatusResponse } from '../shared/messages'; -// Local shape for the sidebar-footer indicator. Mirrors the get_vault_status -// response data (ahead/behind/lastSyncAt/pendingItems). lastSyncAt is a unix -// timestamp in SECONDS, or null when the vault has never synced. -export interface VaultStatus { - ahead: number; - behind: number; - lastSyncAt: number | null; - pendingItems: number; -} +// The indicator consumes exactly the get_vault_status response payload; alias +// it (rather than re-declaring the four fields) so the shape stays single- +// sourced and can't drift from the SW handler. lastSyncAt is a unix timestamp +// in SECONDS, or null when the vault has never synced. +export type VaultStatus = GetVaultStatusResponse['data']; export function renderStatusIndicator(el: HTMLElement, status: VaultStatus): void { const ts = status.lastSyncAt !== null