Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): add Editor to the Content menu, back to the draft last opened (#1477)

Cihand9fd0bf0a5b5
diff --git a/docs/guides/content-editor.mdx b/docs/guides/content-editor.mdx
index 38ae0eff9..30a335db5 100644
--- a/docs/guides/content-editor.mdx
+++ b/docs/guides/content-editor.mdx
@@ -5,9 +5,10 @@ description: "Plan what to write next, start a page yourself or with the Content
## The Content section
-**Content** in the sidebar has three pages:
+**Content** in the sidebar has four pages:
- **Plan** (`/dashboard/content/plan`): what to create, optimize or protect next, ranked.
+- **Editor** (`/dashboard/content/editor`): back to the draft you last opened in the editor for this brand, in this browser. With none, or if that draft was deleted, it opens **New content** to start a page.
- **Opportunities** (`/dashboard/content`): the content opportunities Ansvisor finds in your visibility gaps. See [Content Optimization](/guides/content-optimization).
- **Library** (`/dashboard/content/library`): every page you and the Content Agent wrote or changed in Ansvisor.
diff --git a/web/messages/en.json b/web/messages/en.json
index 178402485..e47d557fe 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -128,6 +128,7 @@
"contentOpportunities": "Opportunities",
"contentLibrary": "Library",
"contentPlan": "Plan",
+ "contentEditor": "Editor",
"toggleSubmenu": "Show or hide {label}"
},
"actionCenter": {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
index e24685c34..6995c1fea 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
@@ -214,6 +214,7 @@ const draft = (over: Partial<ContentDraft> = {}): ContentDraft => ({
agentSince: null,
agentRun: null,
updatedAt: '2026-10-20T10:00:00Z',
+ archivedAt: null,
...over,
});
@@ -380,6 +381,18 @@ describe('the content editor', () => {
expect(container.querySelector('.ProseMirror h1')!.textContent).toBe('Pipeline forecasting');
});
+ it('remembers the draft for Content › Editor, per brand', async () => {
+ getContentDraft.mockResolvedValue(draft());
+ await renderPage();
+ expect(localStorage.getItem('aeo:content-last-draft:b1')).toBe('d1');
+ });
+
+ it('remembers nothing for a draft that isn’t there', async () => {
+ getContentDraft.mockResolvedValue(null);
+ await renderPage();
+ expect(localStorage.getItem('aeo:content-last-draft:b1')).toBeNull();
+ });
+
it('keeps one H1: Heading 1 is off outside the title', async () => {
getContentDraft.mockResolvedValue(draft());
await renderPage();
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.tsx
index b050e5d27..c77bd2a9c 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.tsx
@@ -10,6 +10,7 @@ import { buttonVariants } from '@/components/ui/button-variants';
import { LoadingDots } from '@/components/ui/loading-dots';
import { getContentDraft } from '@/lib/actions/content-drafts';
import { AGENT_POLL_MS, CONTENT_LIBRARY_PATH, type ContentDraft } from '@/lib/content/drafts';
+import { writeLastDraft } from '@/lib/content/last-draft';
import { useBrandStore } from '@/stores/use-brand-store';
import { AgentWriting } from './_agent-writing';
import { DraftEditor } from './_draft-editor';
@@ -35,6 +36,8 @@ export default function ContentEditorPage() {
.then((draft) => {
if (cancelled) return;
setRead(draft ? { id: draftId, draft } : { id: draftId, draft: null, failed: false });
+ // Content › Editor comes back to it.
+ if (draft) writeLastDraft(draft.brandId, draft.id);
})
.catch((err) => {
console.error('Failed to open the draft:', err);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.test.tsx
new file mode 100644
index 000000000..7e3c31d1a
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.test.tsx
@@ -0,0 +1,120 @@
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { NextIntlClientProvider } from 'next-intl';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import messages from '../../../../../../../messages/en.json';
+
+const getContentDraft = vi.fn();
+vi.mock('@/lib/actions/content-drafts', () => ({
+ getContentDraft: (...args: unknown[]) => getContentDraft(...args),
+}));
+const replace = vi.fn();
+vi.mock('@/i18n/navigation', () => ({ useRouter: () => ({ replace }) }));
+const brandState = vi.hoisted(() => ({ activeBrandId: 'b1' as string | null }));
+vi.mock('@/stores/use-brand-store', () => ({
+ useBrandStore: (selector: (state: typeof brandState) => unknown) => selector(brandState),
+}));
+
+const { default: ContentEditorStartPage } = await import('./page');
+const { readLastDraft, writeLastDraft } = await import('@/lib/content/last-draft');
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
+ true;
+
+/** Content › Editor: the draft last opened here, else a new page's start. */
+
+// An in-memory localStorage: the test environment has none.
+const store = new Map<string, string>();
+const memoryStorage = {
+ getItem: (key: string) => store.get(key) ?? null,
+ setItem: (key: string, value: string) => void store.set(key, value),
+ removeItem: (key: string) => void store.delete(key),
+ clear: () => store.clear(),
+};
+Object.defineProperty(window, 'localStorage', { configurable: true, value: memoryStorage });
+
+let container: HTMLDivElement;
+let root: Root;
+
+async function renderPage() {
+ await act(async () => {
+ root.render(
+ <NextIntlClientProvider locale="en" messages={messages} timeZone="UTC">
+ <ContentEditorStartPage />
+ </NextIntlClientProvider>,
+ );
+ });
+}
+
+beforeEach(() => {
+ brandState.activeBrandId = 'b1';
+ getContentDraft.mockReset();
+ replace.mockReset();
+ container = document.createElement('div');
+ root = createRoot(container);
+});
+afterEach(() => {
+ act(() => root.unmount());
+ localStorage.clear();
+});
+
+describe('Content › Editor', () => {
+ it('goes back to the brand’s draft last opened', async () => {
+ writeLastDraft('b1', 'd1');
+ getContentDraft.mockResolvedValue({ id: 'd1', brandId: 'b1', archivedAt: null });
+ await renderPage();
+ expect(getContentDraft).toHaveBeenCalledWith('d1');
+ expect(replace).toHaveBeenCalledWith('/dashboard/content/editor/d1');
+ });
+
+ it('starts a new page when none was opened here', async () => {
+ await renderPage();
+ expect(getContentDraft).not.toHaveBeenCalled();
+ expect(replace).toHaveBeenCalledWith('/dashboard/content/library?new=1');
+ });
+
+ it('starts a new page, and forgets it, when the draft is gone', async () => {
+ writeLastDraft('b1', 'd1');
+ getContentDraft.mockResolvedValue(null);
+ await renderPage();
+ expect(replace).toHaveBeenCalledWith('/dashboard/content/library?new=1');
+ expect(readLastDraft('b1')).toBeNull();
+ });
+
+ it('starts a new page for a draft archived since, or another brand’s', async () => {
+ writeLastDraft('b1', 'd1');
+ getContentDraft.mockResolvedValue({
+ id: 'd1',
+ brandId: 'b1',
+ archivedAt: '2026-10-24T10:00:00Z',
+ });
+ await renderPage();
+ expect(replace).toHaveBeenLastCalledWith('/dashboard/content/library?new=1');
+ expect(readLastDraft('b1')).toBeNull();
+
+ act(() => root.unmount());
+ root = createRoot(container);
+ writeLastDraft('b1', 'd2');
+ getContentDraft.mockResolvedValue({ id: 'd2', brandId: 'b2', archivedAt: null });
+ await renderPage();
+ expect(replace).toHaveBeenLastCalledWith('/dashboard/content/library?new=1');
+ expect(readLastDraft('b1')).toBeNull();
+ });
+
+ it('opens the draft anyway when it can’t be read now (the editor tries again)', async () => {
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
+ writeLastDraft('b1', 'd1');
+ getContentDraft.mockRejectedValue(new Error('offline'));
+ await renderPage();
+ expect(replace).toHaveBeenCalledWith('/dashboard/content/editor/d1');
+ expect(readLastDraft('b1')).toBe('d1');
+ error.mockRestore();
+ });
+
+ it('asks for a brand when none is selected', async () => {
+ brandState.activeBrandId = null;
+ await renderPage();
+ expect(replace).not.toHaveBeenCalled();
+ expect(container.textContent).toContain('Select a brand to see its content.');
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.tsx
new file mode 100644
index 000000000..2e3eb15eb
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/page.tsx
@@ -0,0 +1,64 @@
+'use client';
+
+import { useEffect } from 'react';
+import { useTranslations } from 'next-intl';
+import { useRouter } from '@/i18n/navigation';
+import { LoadingDots } from '@/components/ui/loading-dots';
+import { getContentDraft } from '@/lib/actions/content-drafts';
+import { CONTENT_NEW_PATH, contentEditorPath } from '@/lib/content/drafts';
+import { forgetLastDraft, readLastDraft } from '@/lib/content/last-draft';
+import { useBrandStore } from '@/stores/use-brand-store';
+
+/**
+ * Content › Editor: the brand's draft last opened in the editor, in this
+ * browser; with none (or one deleted or archived since), a new page's start,
+ * the Library with New content open.
+ */
+export default function ContentEditorStartPage() {
+ const t = useTranslations('contentEditor.library');
+ const router = useRouter();
+ const activeBrandId = useBrandStore((s) => s.activeBrandId);
+
+ useEffect(() => {
+ if (!activeBrandId) return;
+ const last = readLastDraft(activeBrandId);
+ if (!last) {
+ router.replace(CONTENT_NEW_PATH);
+ return;
+ }
+ let cancelled = false;
+ getContentDraft(last)
+ .then((draft) => {
+ if (cancelled) return;
+ if (draft?.brandId === activeBrandId && !draft.archivedAt) {
+ router.replace(contentEditorPath(draft.id));
+ return;
+ }
+ // Deleted, archived (not the one to open, 00233), or no longer the
+ // member's to read.
+ forgetLastDraft(activeBrandId);
+ router.replace(CONTENT_NEW_PATH);
+ })
+ // A failed look isn't a draft gone: the editor reads it again.
+ .catch((err) => {
+ console.error('Failed to read the last draft:', err);
+ if (!cancelled) router.replace(contentEditorPath(last));
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [activeBrandId, router]);
+
+ if (!activeBrandId) {
+ return (
+ <div className="flex min-h-[400px] items-center justify-center">
+ <p className="text-muted-foreground">{t('selectBrand')}</p>
+ </div>
+ );
+ }
+ return (
+ <div className="flex min-h-[400px] items-center justify-center" aria-busy="true">
+ <LoadingDots size="md" className="text-muted-foreground" />
+ </div>
+ );
+}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
index 1c615198e..e8c453801 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
@@ -337,6 +337,15 @@ describe('the Content Library', () => {
expect(push).not.toHaveBeenCalled();
});
+ it('opens New content once when the URL asks (Content › Editor with no draft)', async () => {
+ window.history.replaceState(null, '', '/dashboard/content/library?new=1');
+ getContentDrafts.mockResolvedValue([]);
+ await renderPage();
+ expect(document.body.textContent).toContain('Pick how you want to start.');
+ // Closed, it doesn't open again on a reload.
+ expect(window.location.search).toBe('');
+ });
+
it('asks for a brand when none is selected', async () => {
brandState.activeBrandId = null;
await renderPage();
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx
index 4656e3c81..083a6ef7f 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx
@@ -50,7 +50,7 @@ import {
} from '@/lib/content/drafts';
import { siteTypeOf } from '@/lib/content/page-types';
import { formatNumber } from '@/lib/format';
-import { readUrlChoice, writeUrlParams } from '@/lib/url-state';
+import { readUrlChoice, readUrlParam, writeUrlParams } from '@/lib/url-state';
import { useBrandStore } from '@/stores/use-brand-store';
import { BulkSendDialog } from './_bulk-send-dialog';
import { readCmsSources } from './_cms-sources';
@@ -72,7 +72,8 @@ interface LibraryRead {
* Content Agent wrote or changed in Ansvisor, by status, and what was
* archived (00233). A row's menu sets its status; admins and managers also
* send it to the CMS (#1331), archive, restore and delete. The tab lives in
- * the URL (?tab=in_review), so a link can open "Library › In review".
+ * the URL (?tab=in_review), so a link can open "Library › In review";
+ * ?new=1 opens New content (Content › Editor with no draft to go back to).
*/
export default function ContentLibraryPage() {
const t = useTranslations('contentEditor.library');
@@ -111,6 +112,11 @@ export default function ContentLibraryPage() {
// eslint-disable-next-line react-hooks/set-state-in-effect -- one read of the URL after mount
setTab(readUrlChoice('tab', LIBRARY_TABS, 'all'));
setCreated(readUrlChoice('created', CREATED_RANGES, 'all'));
+ // Once: closed, it doesn't open again on a reload.
+ if (readUrlParam('new') === '1') {
+ setStarting(true);
+ writeUrlParams({ new: null });
+ }
}, []);
const { exporting, exportList, exportDraft } = useLibraryExport(activeBrandId);
diff --git a/web/src/components/layout/mobile-nav.tsx b/web/src/components/layout/mobile-nav.tsx
index b445a36a1..5d8111a7a 100644
--- a/web/src/components/layout/mobile-nav.tsx
+++ b/web/src/components/layout/mobile-nav.tsx
@@ -7,6 +7,7 @@ import { dashboardNav } from '@/config/dashboard';
import { BrandSwitcher } from '@/components/layout/brand-switcher';
import {
activeChildHref,
+ childLinkHref,
getDashboardNavLabel,
shouldShowDashboardNavItem,
} from '@/lib/dashboard-navigation';
@@ -167,7 +168,11 @@ export function MobileNav() {
{link}
<div className="ml-7 border-l pl-2">
{item.children.map((child) => (
- <Link key={child.href} href={child.href} onClick={() => setOpen(false)}>
+ <Link
+ key={child.href}
+ href={childLinkHref(child, pathname)}
+ onClick={() => setOpen(false)}
+ >
<span
className={cn(
'flex items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors',
diff --git a/web/src/components/layout/sidebar.tsx b/web/src/components/layout/sidebar.tsx
index 1ae4363f0..9a0984ec5 100644
--- a/web/src/components/layout/sidebar.tsx
+++ b/web/src/components/layout/sidebar.tsx
@@ -11,6 +11,7 @@ import { carriedParams, PROMPTS_BASE } from '@/lib/prompts-routes';
import { dashboardNav } from '@/config/dashboard';
import {
activeChildHref,
+ childLinkHref,
getDashboardNavLabel,
getDashboardNavGroupLabel,
shouldShowDashboardNavItem,
@@ -440,7 +441,7 @@ export function Sidebar() {
return (
<li key={child.href}>
<Link
- href={`${child.href}${carry}`}
+ href={`${childLinkHref(child, pathname)}${carry}`}
data-nav-item="child"
aria-current={childActive ? 'page' : undefined}
className={cn(
diff --git a/web/src/config/dashboard.ts b/web/src/config/dashboard.ts
index 5da9bce95..b116d7cc9 100644
--- a/web/src/config/dashboard.ts
+++ b/web/src/config/dashboard.ts
@@ -27,8 +27,8 @@ export type BrandPrefKey = 'shoppingModeEnabled';
export interface NavChild {
title: string;
href: string;
- /** Other routes that belong to this entry, e.g. the editor to the Library. */
- activeFor?: string[];
+ /** On one of its pages, it links to that page: the Editor stays on the draft open. */
+ keepsPage?: boolean;
/** A short tag after the label, e.g. "New". */
badge?: string;
}
@@ -80,7 +80,8 @@ export const dashboardNav: NavGroup[] = [
requiredFeature: 'ai_agent',
},
// Content Editor (CE-001): a group, like Prompts. The Plan says what to
- // do next (CE-014); Opportunities is today's page and keeps
+ // do next (CE-014); the Editor goes back to the draft last opened, else
+ // starts a new page; Opportunities is today's page and keeps
// /dashboard/content; the Library lists every page written or changed
// in Ansvisor.
{
@@ -90,13 +91,10 @@ export const dashboardNav: NavGroup[] = [
requiredFeature: 'content_optimization',
children: [
{ title: 'Plan', href: '/dashboard/content/plan', badge: 'New' },
+ // A draft open in the editor (CE-004) is under it.
+ { title: 'Editor', href: '/dashboard/content/editor', keepsPage: true },
{ title: 'Opportunities', href: '/dashboard/content' },
- // A draft opens in the editor from the Library (CE-004).
- {
- title: 'Library',
- href: '/dashboard/content/library',
- activeFor: ['/dashboard/content/editor'],
- },
+ { title: 'Library', href: '/dashboard/content/library' },
],
},
{
diff --git a/web/src/lib/actions/content-drafts.ts b/web/src/lib/actions/content-drafts.ts
index 799d9a830..21f08a472 100644
--- a/web/src/lib/actions/content-drafts.ts
+++ b/web/src/lib/actions/content-drafts.ts
@@ -227,7 +227,7 @@ export async function getContentDraft(id: string): Promise<ContentDraft | null>
const { data, error } = await supabase
.from('content_drafts')
.select(
- `id, brand_id, title, page_type, page_type_source, method, status, body_html, author, author_id, source_url, rules, kept_sources, action_id, agent_state, agent_state_at, agent_run, updated_at, ${BRAND_SITE}, actions(action_no)`,
+ `id, brand_id, title, page_type, page_type_source, method, status, body_html, author, author_id, source_url, rules, kept_sources, action_id, agent_state, agent_state_at, agent_run, updated_at, archived_at, ${BRAND_SITE}, actions(action_no)`,
)
.eq('id', id)
.maybeSingle();
@@ -256,6 +256,7 @@ export async function getContentDraft(id: string): Promise<ContentDraft | null>
agentSince: data.agent_state_at,
agentRun: agentRunOf(data.agent_run),
updatedAt: data.updated_at,
+ archivedAt: data.archived_at,
};
}
diff --git a/web/src/lib/content/drafts.ts b/web/src/lib/content/drafts.ts
index 8411124bc..97aecd590 100644
--- a/web/src/lib/content/drafts.ts
+++ b/web/src/lib/content/drafts.ts
@@ -85,9 +85,15 @@ export function isPageType(value: string | null): value is PageType {
/** The Library (CE-001 route). */
export const CONTENT_LIBRARY_PATH = '/dashboard/content/library';
+/** The Library with New content open: a new page's start. */
+export const CONTENT_NEW_PATH = `${CONTENT_LIBRARY_PATH}?new=1`;
+
+/** Content › Editor: the draft last opened here, else a new page's start. */
+export const CONTENT_EDITOR_PATH = '/dashboard/content/editor';
+
/** Where a draft opens: the editor (CE-004). */
export function contentEditorPath(draftId: string) {
- return `/dashboard/content/editor/${draftId}`;
+ return `${CONTENT_EDITOR_PATH}/${draftId}`;
}
/**
@@ -171,6 +177,8 @@ export interface ContentDraft {
/** Which run that is, for every device: a failed rewrite is tried again as one. */
agentRun: AgentRun;
updatedAt: string;
+ /** When an admin or manager archived it (00233): Content › Editor doesn't go back to it. */
+ archivedAt: string | null;
}
/**
diff --git a/web/src/lib/content/last-draft.test.ts b/web/src/lib/content/last-draft.test.ts
new file mode 100644
index 000000000..b8c6849a1
--- /dev/null
+++ b/web/src/lib/content/last-draft.test.ts
@@ -0,0 +1,46 @@
+import { afterEach, describe, expect, it } from 'vitest';
+import { forgetLastDraft, readLastDraft, writeLastDraft } from './last-draft';
+
+/** The draft last opened in the editor, per brand (Content › Editor). */
+
+// An in-memory localStorage: the test environment has none.
+const store = new Map<string, string>();
+const memoryStorage = {
+ getItem: (key: string) => store.get(key) ?? null,
+ setItem: (key: string, value: string) => void store.set(key, value),
+ removeItem: (key: string) => void store.delete(key),
+ clear: () => store.clear(),
+};
+Object.defineProperty(window, 'localStorage', { configurable: true, value: memoryStorage });
+
+afterEach(() => {
+ Object.defineProperty(window, 'localStorage', { configurable: true, value: memoryStorage });
+ localStorage.clear();
+});
+
+describe('last draft', () => {
+ it('keeps the draft last opened, per brand', () => {
+ expect(readLastDraft('b1')).toBeNull();
+ writeLastDraft('b1', 'd1');
+ writeLastDraft('b1', 'd2');
+ writeLastDraft('b2', 'd9');
+ expect(readLastDraft('b1')).toBe('d2');
+ expect(readLastDraft('b2')).toBe('d9');
+ forgetLastDraft('b1');
+ expect(readLastDraft('b1')).toBeNull();
+ expect(readLastDraft('b2')).toBe('d9');
+ });
+
+ it('keeps none when storage is unavailable (private mode)', () => {
+ const blocked = () => {
+ throw new Error('denied');
+ };
+ Object.defineProperty(window, 'localStorage', {
+ configurable: true,
+ value: { getItem: blocked, setItem: blocked, removeItem: blocked },
+ });
+ expect(() => writeLastDraft('b1', 'd1')).not.toThrow();
+ expect(readLastDraft('b1')).toBeNull();
+ expect(() => forgetLastDraft('b1')).not.toThrow();
+ });
+});
diff --git a/web/src/lib/content/last-draft.ts b/web/src/lib/content/last-draft.ts
new file mode 100644
index 000000000..554366a95
--- /dev/null
+++ b/web/src/lib/content/last-draft.ts
@@ -0,0 +1,30 @@
+/**
+ * The draft a member last opened in the editor, per brand: Content › Editor
+ * goes back to it. Kept in this browser, as the editor's panel is; storage
+ * unavailable (private mode) leaves none.
+ */
+const lastDraftKey = (brandId: string) => `aeo:content-last-draft:${brandId}`;
+
+export function readLastDraft(brandId: string): string | null {
+ try {
+ return localStorage.getItem(lastDraftKey(brandId));
+ } catch {
+ return null;
+ }
+}
+
+export function writeLastDraft(brandId: string, draftId: string): void {
+ try {
+ localStorage.setItem(lastDraftKey(brandId), draftId);
+ } catch {
+ // Not kept: Editor starts a new page instead.
+ }
+}
+
+export function forgetLastDraft(brandId: string): void {
+ try {
+ localStorage.removeItem(lastDraftKey(brandId));
+ } catch {
+ // Nothing kept to forget.
+ }
+}
diff --git a/web/src/lib/dashboard-navigation.test.ts b/web/src/lib/dashboard-navigation.test.ts
index 2d56aca10..a02e8e8af 100644
--- a/web/src/lib/dashboard-navigation.test.ts
+++ b/web/src/lib/dashboard-navigation.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import { dashboardNav } from '@/config/dashboard';
import {
activeChildHref,
+ childLinkHref,
dashboardNavLabelKeys,
getDashboardNavGroupLabel,
getDashboardNavLabel,
@@ -40,19 +41,16 @@ describe('getDashboardNavLabel', () => {
});
// Content Editor (CE-001): Content is a group, the Plan first and new
- // (CE-014); Opportunities keeps today's route.
- it('lists the Plan, Opportunities and the Library under Content', () => {
+ // (CE-014), then the Editor; Opportunities keeps today's route.
+ it('lists the Plan, the Editor, Opportunities and the Library under Content', () => {
const items = dashboardNav.flatMap((group) => group.items);
const content = items.find((item) => item.title === 'Content')!;
expect(content.href).toBe('/dashboard/content');
expect(content.children).toEqual([
{ title: 'Plan', href: '/dashboard/content/plan', badge: 'New' },
+ { title: 'Editor', href: '/dashboard/content/editor', keepsPage: true },
{ title: 'Opportunities', href: '/dashboard/content' },
- {
- title: 'Library',
- href: '/dashboard/content/library',
- activeFor: ['/dashboard/content/editor'],
- },
+ { title: 'Library', href: '/dashboard/content/library' },
]);
});
@@ -140,10 +138,13 @@ describe('activeChildHref', () => {
);
});
- it('marks the Library while a draft is open in the editor', () => {
+ it('marks the Editor while a draft is open in it', () => {
const items = dashboardNav.flatMap((group) => group.items);
const children = items.find((item) => item.title === 'Content')!.children!;
expect(activeChildHref(children, '/dashboard/content/editor/d1')).toBe(
+ '/dashboard/content/editor',
+ );
+ expect(activeChildHref(children, '/dashboard/content/library')).toBe(
'/dashboard/content/library',
);
expect(activeChildHref(children, '/dashboard/content/3f2a')).toBe('/dashboard/content');
@@ -164,3 +165,24 @@ describe('activeChildHref', () => {
expect(activeChildHref(content, '/dashboard/audit')).toBeNull();
});
});
+
+describe('childLinkHref', () => {
+ const children = dashboardNav
+ .flatMap((group) => group.items)
+ .find((item) => item.title === 'Content')!.children!;
+ const editor = children.find((c) => c.title === 'Editor')!;
+ const library = children.find((c) => c.title === 'Library')!;
+
+ it('keeps the Editor on the draft open, so clicking it doesn’t open it again', () => {
+ expect(childLinkHref(editor, '/dashboard/content/editor/d1')).toBe(
+ '/dashboard/content/editor/d1',
+ );
+ expect(childLinkHref(editor, '/dashboard/content/library')).toBe('/dashboard/content/editor');
+ });
+
+ it('links any other entry to its own route', () => {
+ expect(childLinkHref(library, '/dashboard/content/library')).toBe('/dashboard/content/library');
+ const topics = { title: 'Topics', href: '/dashboard/prompts/topics' };
+ expect(childLinkHref(topics, '/dashboard/prompts/topics/t1')).toBe('/dashboard/prompts/topics');
+ });
+});
diff --git a/web/src/lib/dashboard-navigation.ts b/web/src/lib/dashboard-navigation.ts
index 2d87e3b4f..a343d03e5 100644
--- a/web/src/lib/dashboard-navigation.ts
+++ b/web/src/lib/dashboard-navigation.ts
@@ -18,6 +18,7 @@ export const dashboardNavLabelKeys: Record<string, string> = {
'Prompts Insights': 'promptsInsights',
Content: 'content',
Plan: 'contentPlan',
+ Editor: 'contentEditor',
Opportunities: 'contentOpportunities',
Library: 'contentLibrary',
'Site Audit': 'audit',
@@ -46,27 +47,33 @@ export function getDashboardNavLabel(title: string, t: Translator): string {
}
/**
- * The submenu entry the current page belongs to: its own route, one it is
- * `activeFor` (the editor, for the Library), or a page under either (a
- * topic's page sits under Topics). When one entry's route holds another's
+ * The submenu entry the current page belongs to: its own route, or a page
+ * under it (a topic's page sits under Topics, a draft under the Editor).
+ * When one entry's route holds another's
* (Opportunities is /dashboard/content, the Library is
* /dashboard/content/library), the longer match wins, so only one is current.
*/
export function activeChildHref(children: NavChild[], pathname: string): string | null {
let best: string | null = null;
let bestLength = -1;
- for (const child of children) {
- for (const route of [child.href, ...(child.activeFor ?? [])]) {
- const matches = pathname === route || pathname.startsWith(`${route}/`);
- if (matches && route.length > bestLength) {
- best = child.href;
- bestLength = route.length;
- }
+ for (const { href } of children) {
+ const matches = pathname === href || pathname.startsWith(`${href}/`);
+ if (matches && href.length > bestLength) {
+ best = href;
+ bestLength = href.length;
}
}
return best;
}
+/**
+ * Where a submenu entry links: its route, or the page open under it when it
+ * keeps it (the Editor, on a draft: clicking it doesn't open the draft again).
+ */
+export function childLinkHref(child: NavChild, pathname: string): string {
+ return child.keepsPage && pathname.startsWith(`${child.href}/`) ? pathname : child.href;
+}
+
/** Brand preferences hide a navigation item entirely; they are intentionally
* separate from plan gates, which render a visible but disabled item. */
export function shouldShowDashboardNavItem(