diff --git a/src/lib/api/accounts.test.ts b/src/lib/api/accounts.test.ts index cee7523ae..636576c41 100644 --- a/src/lib/api/accounts.test.ts +++ b/src/lib/api/accounts.test.ts @@ -3,7 +3,8 @@ import { vi, test, describe, it, expect, beforeEach, afterEach } from "vitest"; import { BASE_API_URL } from "@/config/config"; import * as fixtures from "@/test/fixtures/accounts"; -import { getMe, getOrg } from "./accounts"; +import { getMe, getOrg, userDocs } from "./accounts"; +import { slugify } from "@/util/string.js"; describe("getMe", async () => { let mockFetch; @@ -62,3 +63,15 @@ test("getOrg", async () => { test.todo("users.get"); test.todo("users.list"); + +describe("utility methods", () => { + test("userDocs", () => { + expect(userDocs(fixtures.me, "public")).toStrictEqual( + `+user:${slugify(fixtures.me.name)}-${fixtures.me.id} access:public`, + ); + + expect(userDocs(fixtures.me, "private")).toStrictEqual( + `+user:${slugify(fixtures.me.name)}-${fixtures.me.id} access:private`, + ); + }); +}); diff --git a/src/lib/api/accounts.ts b/src/lib/api/accounts.ts index 58ac435ee..d3b375f0b 100644 --- a/src/lib/api/accounts.ts +++ b/src/lib/api/accounts.ts @@ -1,5 +1,7 @@ import type { Maybe, User, Org } from "@/api/types"; +import type { Access } from "./types"; import { BASE_API_URL } from "@/config/config.js"; +import { slugify } from "@/util/string.js"; type Fetch = typeof globalThis.fetch; @@ -21,3 +23,14 @@ export async function getOrg(fetch: Fetch, id: number): Promise { const resp = await fetch(endpoint, { credentials: "include" }); return resp.json(); } + +// link helpers + +/** + * Generate search params for a user's documents + * @param user + * @param access + */ +export function userDocs(user: User, access: Access): string { + return `+user:${slugify(user.name)}-${user.id} access:${access}`; +} diff --git a/src/lib/api/fixtures/documents/pending.json b/src/lib/api/fixtures/documents/pending.json new file mode 100644 index 000000000..b17670a0d --- /dev/null +++ b/src/lib/api/fixtures/documents/pending.json @@ -0,0 +1,9 @@ +[ + { + "doc_id": 20000033, + "images": 2, + "texts": 2, + "text_positions": 5, + "pages": 11 + } +] diff --git a/src/lib/api/types.d.ts b/src/lib/api/types.d.ts index 8ad8ff6ce..28ce6be3e 100644 --- a/src/lib/api/types.d.ts +++ b/src/lib/api/types.d.ts @@ -191,4 +191,12 @@ export interface OCREngine { help?: string; } +export interface Pending { + doc_id: number; + images: number; + texts: number; + text_positions: number; + pages: number; +} + export type ProjectMembershipList = Page; diff --git a/src/lib/components/forms/DocumentUpload.svelte b/src/lib/components/forms/DocumentUpload.svelte index 89e1e2d92..9ecebe790 100644 --- a/src/lib/components/forms/DocumentUpload.svelte +++ b/src/lib/components/forms/DocumentUpload.svelte @@ -1,6 +1,7 @@ - - = getContext("me"); const org: Writable = getContext("org"); $: query = $page.url.searchParams.get("q") || ""; - // +user:chris-amico-1020 +access:public - $: mine = $me ? `+user:${slugify($me.name)}-${$me.id}` : ""; - $: minePublic = `${mine} +access:public`; - $: minePrivate = `${mine} +access:private`; + $: minePublic = userDocs($me, "public"); + $: minePrivate = userDocs($me, "private"); // +organization:muckrock-125 $: orgDocs = $org ? `+organization:${slugify($org.name)}-${$org.id}` : "";