refactor(ext): simplify Phase 6 — alias VaultStatus + reuse listItems

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 <noreply@anthropic.com>
This commit is contained in:
adlee-was-taken
2026-05-31 21:54:42 -04:00
parent c662db2875
commit f4b4cf3db7
2 changed files with 7 additions and 12 deletions

View File

@@ -566,9 +566,7 @@ export function handleGetVaultStatus(
}, },
): GetVaultStatusResponse | { ok: false; error: string } { ): GetVaultStatusResponse | { ok: false; error: string } {
if (!state.gitHost) return { ok: false, error: 'vault_locked' }; if (!state.gitHost) return { ok: false, error: 'vault_locked' };
const pendingItems = state.manifest const pendingItems = state.manifest ? listItems(state.manifest).length : 0;
? Object.values(state.manifest.items).filter((e) => e.trashed_at === undefined).length
: 0;
return { return {
ok: true, ok: true,
data: { data: {

View File

@@ -5,16 +5,13 @@ import {
GLYPH_PENDING, GLYPH_PENDING,
} from '../shared/glyphs'; } from '../shared/glyphs';
import { relativeTime } from '../shared/relative-time'; import { relativeTime } from '../shared/relative-time';
import type { GetVaultStatusResponse } from '../shared/messages';
// Local shape for the sidebar-footer indicator. Mirrors the get_vault_status // The indicator consumes exactly the get_vault_status response payload; alias
// response data (ahead/behind/lastSyncAt/pendingItems). lastSyncAt is a unix // it (rather than re-declaring the four fields) so the shape stays single-
// timestamp in SECONDS, or null when the vault has never synced. // sourced and can't drift from the SW handler. lastSyncAt is a unix timestamp
export interface VaultStatus { // in SECONDS, or null when the vault has never synced.
ahead: number; export type VaultStatus = GetVaultStatusResponse['data'];
behind: number;
lastSyncAt: number | null;
pendingItems: number;
}
export function renderStatusIndicator(el: HTMLElement, status: VaultStatus): void { export function renderStatusIndicator(el: HTMLElement, status: VaultStatus): void {
const ts = status.lastSyncAt !== null const ts = status.lastSyncAt !== null