Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat([issue-713]): pure nav working-set helpers (MRU + pins)

Adam Eivyc7cc65dc5f8c
diff --git a/client/src/utils/navWorkingSet.js b/client/src/utils/navWorkingSet.js
new file mode 100644
index 0000000000..79ba7071bf
--- /dev/null
+++ b/client/src/utils/navWorkingSet.js
@@ -0,0 +1,29 @@
+// Pure working-set helpers for the sidebar Pinned + Recent sections.
+// No DOM / localStorage access here — callers (useNavWorkingSet) own I/O so
+// this logic is testable in node. Lists are plain string[] of route paths,
+// most-recent-first for Recent and insertion-order for Pinned.
+
+export const RECENT_KEY = 'portos-nav-recent';
+export const PINNED_KEY = 'portos-nav-pinned';
+export const RECENT_CAP = 5;
+
+const asList = (list) => (Array.isArray(list) ? list : []);
+const isPath = (p) => typeof p === 'string' && p.length > 0;
+
+// Move/insert `path` to the front of the MRU list, dedup, cap at RECENT_CAP.
+export const recordVisit = (path, list) => {
+ const current = asList(list);
+ if (!isPath(path)) return current;
+ return [path, ...current.filter((p) => p !== path)].slice(0, RECENT_CAP);
+};
+
+// Add `path` if absent, remove it if present.
+export const togglePin = (path, list) => {
+ const current = asList(list);
+ if (!isPath(path)) return current;
+ return current.includes(path)
+ ? current.filter((p) => p !== path)
+ : [...current, path];
+};
+
+export const isPinned = (path, list) => asList(list).includes(path);
diff --git a/client/src/utils/navWorkingSet.test.js b/client/src/utils/navWorkingSet.test.js
new file mode 100644
index 0000000000..02693b404b
--- /dev/null
+++ b/client/src/utils/navWorkingSet.test.js
@@ -0,0 +1,66 @@
+import { describe, it, expect } from 'vitest';
+import {
+ RECENT_KEY, PINNED_KEY, RECENT_CAP,
+ recordVisit, togglePin, isPinned,
+} from './navWorkingSet.js';
+
+describe('navWorkingSet — constants', () => {
+ it('exposes stable localStorage keys and a cap of 5', () => {
+ expect(RECENT_KEY).toBe('portos-nav-recent');
+ expect(PINNED_KEY).toBe('portos-nav-pinned');
+ expect(RECENT_CAP).toBe(5);
+ });
+});
+
+describe('recordVisit', () => {
+ it('prepends a new path most-recent-first', () => {
+ expect(recordVisit('/b', ['/a'])).toEqual(['/b', '/a']);
+ });
+
+ it('dedups — moves an existing path to the front without duplicating', () => {
+ expect(recordVisit('/a', ['/b', '/a', '/c'])).toEqual(['/a', '/b', '/c']);
+ });
+
+ it('caps the list at RECENT_CAP entries', () => {
+ const result = recordVisit('/new', ['/1', '/2', '/3', '/4', '/5']);
+ expect(result).toEqual(['/new', '/1', '/2', '/3', '/4']);
+ expect(result).toHaveLength(RECENT_CAP);
+ });
+
+ it('ignores falsy / non-string paths (returns the list unchanged)', () => {
+ expect(recordVisit('', ['/a'])).toEqual(['/a']);
+ expect(recordVisit(null, ['/a'])).toEqual(['/a']);
+ expect(recordVisit(undefined, ['/a'])).toEqual(['/a']);
+ expect(recordVisit(42, ['/a'])).toEqual(['/a']);
+ });
+
+ it('tolerates a non-array current list', () => {
+ expect(recordVisit('/a', null)).toEqual(['/a']);
+ expect(recordVisit('/a', undefined)).toEqual(['/a']);
+ });
+});
+
+describe('togglePin / isPinned', () => {
+ it('adds a path when absent', () => {
+ expect(togglePin('/a', [])).toEqual(['/a']);
+ });
+
+ it('removes a path when present', () => {
+ expect(togglePin('/a', ['/a', '/b'])).toEqual(['/b']);
+ });
+
+ it('ignores falsy paths', () => {
+ expect(togglePin('', ['/a'])).toEqual(['/a']);
+ expect(togglePin(null, ['/a'])).toEqual(['/a']);
+ });
+
+ it('tolerates a non-array current list', () => {
+ expect(togglePin('/a', null)).toEqual(['/a']);
+ });
+
+ it('isPinned reports membership', () => {
+ expect(isPinned('/a', ['/a', '/b'])).toBe(true);
+ expect(isPinned('/c', ['/a', '/b'])).toBe(false);
+ expect(isPinned('/a', null)).toBe(false);
+ });
+});