diff --git a/.storybook/decorators/ViewerContextDecorator.svelte b/.storybook/decorators/ViewerContextDecorator.svelte index ddab5b2a2..54053bb99 100644 --- a/.storybook/decorators/ViewerContextDecorator.svelte +++ b/.storybook/decorators/ViewerContextDecorator.svelte @@ -1,18 +1,8 @@ - + + + diff --git a/src/lib/api/documents.ts b/src/lib/api/documents.ts index c45c77597..486566b34 100644 --- a/src/lib/api/documents.ts +++ b/src/lib/api/documents.ts @@ -20,6 +20,7 @@ import type { WriteMode, ViewerMode, ValidationError, + Nullable, } from "./types"; import { writable, type Writable } from "svelte/store"; @@ -550,13 +551,13 @@ export function pageHashUrl(page: number): string { * * @param hash URL hash */ -export function pageFromHash(hash: string): number { +export function pageFromHash(hash: string): Nullable { const re = /^#document\/p(\d+)/; // match pages and notes const match = re.exec(hash); - if (!match) return 1; + if (!match) return null; - return +match[1] || 1; + return +match[1] || null; } /** diff --git a/src/lib/api/notes.ts b/src/lib/api/notes.ts index ba0fd63b5..9635f37d5 100644 --- a/src/lib/api/notes.ts +++ b/src/lib/api/notes.ts @@ -159,10 +159,7 @@ export function canonicalNoteUrl(document: Document, note: Note): URL { * @example https://www.documentcloud.org/documents/2622-agreement-between-conservatives-and-liberal-democrats-to-form-a-coalition-government/#document/p3/a557 */ export function noteUrl(document: Document, note: Note): URL { - return new URL( - `#document/p${note.page_number + 1}/a${note.id}`, - canonicalUrl(document), - ); + return new URL(noteHashUrl(note), canonicalUrl(document)); } /** diff --git a/src/lib/api/tests/documents.test.ts b/src/lib/api/tests/documents.test.ts index 48f3e8cc5..6f7d937cf 100644 --- a/src/lib/api/tests/documents.test.ts +++ b/src/lib/api/tests/documents.test.ts @@ -714,7 +714,7 @@ describe("document helper methods", () => { expect(documents.pageFromHash(hash)).toStrictEqual(10); // invalid hash returns page 1 - expect(documents.pageFromHash("#nopage")).toStrictEqual(1); + expect(documents.pageFromHash("#nopage")).toStrictEqual(null); // match a note hash expect(documents.pageFromHash("#document/p2/a2000002")).toStrictEqual(2); diff --git a/src/lib/components/embeds/DocumentEmbed.svelte b/src/lib/components/embeds/DocumentEmbed.svelte index 015d4f482..672729955 100644 --- a/src/lib/components/embeds/DocumentEmbed.svelte +++ b/src/lib/components/embeds/DocumentEmbed.svelte @@ -1,7 +1,9 @@ + @@ -48,7 +50,7 @@
-
+