Skip to content

Commit

Permalink
Merge pull request #552 from MuckRock/sveltekit-viewer-notes
Browse files Browse the repository at this point in the history
sveltekit viewer notes
  • Loading branch information
eyeseast authored May 31, 2024
2 parents 0cc30ee + 4468773 commit 1fab939
Show file tree
Hide file tree
Showing 29 changed files with 1,295 additions and 98 deletions.
18 changes: 17 additions & 1 deletion src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@
"modifyDesc": "Rearrange, rotate, delete, insert, and split pages.",
"info": "Edit Document Info",
"infoDesc": "Modify document information like description and related URL.",
"data": "Edit Tags and Data",
"dataDesc": "Add tags and key/value pairs to categorize your document.",
"sections": "Edit Sections",
"sectionsDesc": "Add sections to organize your document with a table of contents.",
Expand All @@ -838,11 +837,28 @@
"title": "Add-Ons",
"pinned": "Pinned add-ons will appear here"
},
"data": {
"title": "Data & Tags",
"empty": "Use tags or key/value data to organize documents",
"tags": "Tags",
"data": "Data"
},
"projects": {
"title": "Projects",
"pinned": "Pinned projects will appear here"
},
"toc": {
"empty": "Sections organize your document with a table of contents",
"notes": "Notes",
"pageAbbrev": "p.",
"sections": "Sections",
"title": "Notes & Sections"
}
},
"notes": {
"empty": "Add notes to highlight and comment on your document",
"cta": "Annotate this document"
},
"viewer": {
"notFound": "Document not found",
"notFoundDesc": "The document you requested either does not exist or you lack permission to access it",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/api/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ describe("document helper methods", () => {

// invalid hash returns page 1
expect(documents.pageFromHash("#nopage")).toStrictEqual(1);

// match a note hash
expect(documents.pageFromHash("#document/p2/a2000002")).toStrictEqual(2);
});

test("pageUrl", ({ document }) => {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/api/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function get(
"projects",
"revisions",
"sections",
"notes",
"notes.user",
];
endpoint.searchParams.set("expand", expand.join(","));

Expand Down Expand Up @@ -293,12 +293,13 @@ export function pageHashUrl(page: number): string {
}

/**
* The opposite of pageHashUrl, extracting a page number from a URL hash
* The opposite of pageHashUrl, extracting a page number from a URL hash.
* Note that this will also match note hash URLs, which use the same prefix.
*
* @param hash URL hash
*/
export function pageFromHash(hash: string): number {
const re = /^#document\/p(\d+)$/;
const re = /^#document\/p(\d+)/; // match pages and notes
const match = re.exec(hash);

if (!match) return 1;
Expand Down
180 changes: 165 additions & 15 deletions src/lib/api/fixtures/documents/document-expanded.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@
"notes": [
{
"id": 551,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 0,
"access": "public",
Expand All @@ -90,7 +100,17 @@
},
{
"id": 549,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 0,
"access": "public",
Expand All @@ -106,7 +126,17 @@
},
{
"id": 550,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 0,
"access": "public",
Expand All @@ -122,7 +152,17 @@
},
{
"id": 552,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 0,
"access": "public",
Expand All @@ -138,7 +178,17 @@
},
{
"id": 554,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 1,
"access": "public",
Expand All @@ -154,7 +204,17 @@
},
{
"id": 553,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 1,
"access": "public",
Expand All @@ -170,7 +230,17 @@
},
{
"id": 556,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 2,
"access": "public",
Expand All @@ -186,7 +256,17 @@
},
{
"id": 555,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 2,
"access": "public",
Expand All @@ -202,7 +282,17 @@
},
{
"id": 557,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 2,
"access": "public",
Expand All @@ -218,7 +308,17 @@
},
{
"id": 558,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 2,
"access": "public",
Expand All @@ -234,7 +334,17 @@
},
{
"id": 560,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 4,
"access": "public",
Expand All @@ -250,7 +360,17 @@
},
{
"id": 559,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 4,
"access": "public",
Expand All @@ -266,7 +386,17 @@
},
{
"id": 562,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 5,
"access": "public",
Expand All @@ -282,7 +412,17 @@
},
{
"id": 561,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 5,
"access": "public",
Expand All @@ -298,7 +438,17 @@
},
{
"id": 563,
"user": 126,
"user": {
"id": 126,
"avatar_url": "",
"name": "Chris Amico",
"organization": 14187,
"organizations": [14187],
"admin_organizations": [14187],
"username": "ChrisAmico_lSozDZNW",
"uuid": "caea06a2-ee1c-43e6-865a-a09078522bf1",
"verified_journalist": true
},
"organization": 60,
"page_number": 6,
"access": "public",
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions src/lib/api/notes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ describe("note helper methods", () => {
);
});

test("noteHashUrl", () => {
expect(notes.noteHashUrl(n)).toStrictEqual("#document/p3/a557");
});

test("noteFromHash", () => {
const hash = notes.noteHashUrl(n);

expect(notes.noteFromHash(hash)).toStrictEqual(n.id);
});

test("width", () => {
expect(notes.width(n)).toStrictEqual(n.x2 - n.x1);
});
Expand Down
Loading

0 comments on commit 1fab939

Please sign in to comment.