From 124f794535ec0138978d2dfe1183cebe7473f727 Mon Sep 17 00:00:00 2001 From: chihlasm Date: Mon, 16 Mar 2026 00:47:41 -0400 Subject: [PATCH] feat: add recentFlows localStorage utility for command palette empty state Tracks recently visited flows (capped at 10) with deduplication by id, surfaced in command palette when query is empty. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/lib/recentFlows.ts | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 frontend/src/lib/recentFlows.ts diff --git a/frontend/src/lib/recentFlows.ts b/frontend/src/lib/recentFlows.ts new file mode 100644 index 00000000..9f8c033f --- /dev/null +++ b/frontend/src/lib/recentFlows.ts @@ -0,0 +1,40 @@ +/** + * localStorage utility for tracking recently visited flows. + */ + +const STORAGE_KEY = 'rf_recent_flows' +const MAX_ENTRIES = 10 + +export interface RecentFlow { + id: string + name: string + tree_type: string + timestamp: number +} + +export function getRecentFlows(limit = 5): RecentFlow[] { + try { + const raw = localStorage.getItem(STORAGE_KEY) + if (!raw) return [] + const parsed = JSON.parse(raw) as RecentFlow[] + return Array.isArray(parsed) ? parsed.slice(0, limit) : [] + } catch { + return [] + } +} + +export function addRecentFlow(flow: Omit): void { + try { + const existing = getRecentFlows(MAX_ENTRIES) + // Deduplicate by id — remove any existing entry with the same id + const deduped = existing.filter(f => f.id !== flow.id) + // Add to front with current timestamp + const updated: RecentFlow[] = [ + { ...flow, timestamp: Date.now() }, + ...deduped, + ].slice(0, MAX_ENTRIES) + localStorage.setItem(STORAGE_KEY, JSON.stringify(updated)) + } catch { + // Silently ignore localStorage errors (private browsing, quota exceeded) + } +}