From 5a21dfc081ebffa557fca8f144459685efc4a4d7 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 3 Dec 2024 16:39:59 -0500 Subject: [PATCH 1/5] Debugging project pagination --- src/routes/(app)/projects/+page.svelte | 21 +++++++++++---------- src/routes/(app)/projects/+page.ts | 21 ++++++++------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/routes/(app)/projects/+page.svelte b/src/routes/(app)/projects/+page.svelte index e3288b75f..950164620 100644 --- a/src/routes/(app)/projects/+page.svelte +++ b/src/routes/(app)/projects/+page.svelte @@ -34,17 +34,18 @@ $: query = data.query; $: projects = data.projects.results; - $: next = data.projects.next; - $: previous = data.projects.previous; + $: next = data.projects.next; // this will be an API url with a cursor + $: previous = data.projects.previous; // this will be an API url with a cursor function paginate(u: Nullable) { if (!u) return; - u = new URL(u); - const target = new URL($page.url); - - const cursor = u.searchParams.get("cursor"); - if (cursor) target.searchParams.set("cursor", cursor); - goto(target); + const pageUrl = new URL(u); + const gotoUrl = new URL($page.url); + // get the cursor out of the pageUrl, pass it to the gotoUrl + const cursor = pageUrl.searchParams.get("cursor"); + if (cursor) gotoUrl.searchParams.set("cursor", cursor); + console.log(gotoUrl.toString()); + goto(gotoUrl); } @@ -108,8 +109,8 @@ slot="center" has_next={Boolean(next)} has_previous={Boolean(previous)} - on:next={(e) => paginate(next)} - on:previous={(e) => paginate(previous)} + on:next={() => paginate(next)} + on:previous={() => paginate(previous)} /> diff --git a/src/routes/(app)/projects/+page.ts b/src/routes/(app)/projects/+page.ts index e6c8d8c53..d9de9fe7d 100644 --- a/src/routes/(app)/projects/+page.ts +++ b/src/routes/(app)/projects/+page.ts @@ -1,7 +1,7 @@ -import type { ProjectResults } from "$lib/api/types"; +import type { Maybe, ProjectResults } from "$lib/api/types"; import { DEFAULT_PER_PAGE } from "@/config/config.js"; -import { getOwned, getShared, list } from "$lib/api/projects"; +import { list } from "$lib/api/projects"; type ProjectFilter = "owned" | "shared" | "public"; @@ -24,36 +24,31 @@ export async function load({ url, parent, fetch }) { filter = "public"; } - let projects: ProjectResults = { + const defaultProjects: ProjectResults = { results: [], next: null, previous: null, }; + let data: Maybe; let error: unknown; if (me && filter === "owned") { - ({ data: projects = projects, error } = await list( - { ...params, owned_by_user: true }, - fetch, - )); + ({ data, error } = await list({ ...params, owned_by_user: true }, fetch)); } if (me && filter === "shared") { - ({ data: projects = projects, error } = await list( - { ...params, is_shared: true }, - fetch, - )); + ({ data, error } = await list({ ...params, is_shared: true }, fetch)); } if (filter === "public") { - ({ data: projects = projects, error } = await list(params, fetch)); + ({ data, error } = await list(params, fetch)); } return { error, list: filter, - projects, + projects: data ?? defaultProjects, query, cursor, per_page, From 5a8bf022b0c0ed83853b71351a08fa078e0c0447 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 3 Dec 2024 16:49:51 -0500 Subject: [PATCH 2/5] Debug logging --- src/routes/(app)/projects/+page.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/(app)/projects/+page.svelte b/src/routes/(app)/projects/+page.svelte index 950164620..2865eb1ee 100644 --- a/src/routes/(app)/projects/+page.svelte +++ b/src/routes/(app)/projects/+page.svelte @@ -37,6 +37,8 @@ $: next = data.projects.next; // this will be an API url with a cursor $: previous = data.projects.previous; // this will be an API url with a cursor + $: console.log(data.projects); + function paginate(u: Nullable) { if (!u) return; const pageUrl = new URL(u); From bcb98523eb360988a182454dd9469f4f93089fc9 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 3 Dec 2024 16:51:44 -0500 Subject: [PATCH 3/5] Ignore progress bars in Chromatic --- src/lib/components/processing/Process.svelte | 8 ++++---- src/lib/components/viewer/LoadingToolbar.svelte | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/components/processing/Process.svelte b/src/lib/components/processing/Process.svelte index 0774af00d..e51149290 100644 --- a/src/lib/components/processing/Process.svelte +++ b/src/lib/components/processing/Process.svelte @@ -47,13 +47,13 @@ {/if} {#if ["success", "failure", "cancelled"].includes(status)} - + {:else if status === "queued"} - + {:else if progress} - + {:else} - + {/if} diff --git a/src/lib/components/viewer/LoadingToolbar.svelte b/src/lib/components/viewer/LoadingToolbar.svelte index e32e599c3..659dbdc17 100644 --- a/src/lib/components/viewer/LoadingToolbar.svelte +++ b/src/lib/components/viewer/LoadingToolbar.svelte @@ -9,9 +9,9 @@

Loading PDF…

{#if progress} - + {:else} - + {/if}
From 1385f69a79669af8104b4a71009a75ec0a7371aa Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 3 Dec 2024 17:00:52 -0500 Subject: [PATCH 4/5] Don't make pagination dispatch based on page # --- src/lib/components/common/Paginator.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/components/common/Paginator.svelte b/src/lib/components/common/Paginator.svelte index 3b8497703..bccfd6f7a 100644 --- a/src/lib/components/common/Paginator.svelte +++ b/src/lib/components/common/Paginator.svelte @@ -31,11 +31,11 @@ } function previous() { - if (page) dispatch("previous", page - 1); + if (has_previous) dispatch("previous", (page ?? 0) - 1); } function next() { - if (page) dispatch("next", page + 1); + if (has_next) dispatch("next", (page ?? 0) + 1); } function goTo(page: number) { From cfe462e245bb5e73ec61de083e6a2efae5c8e550 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 3 Dec 2024 17:07:08 -0500 Subject: [PATCH 5/5] Remove logging statements --- src/routes/(app)/projects/+page.svelte | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/routes/(app)/projects/+page.svelte b/src/routes/(app)/projects/+page.svelte index 2865eb1ee..35f9f23b0 100644 --- a/src/routes/(app)/projects/+page.svelte +++ b/src/routes/(app)/projects/+page.svelte @@ -37,8 +37,6 @@ $: next = data.projects.next; // this will be an API url with a cursor $: previous = data.projects.previous; // this will be an API url with a cursor - $: console.log(data.projects); - function paginate(u: Nullable) { if (!u) return; const pageUrl = new URL(u); @@ -46,7 +44,6 @@ // get the cursor out of the pageUrl, pass it to the gotoUrl const cursor = pageUrl.searchParams.get("cursor"); if (cursor) gotoUrl.searchParams.set("cursor", cursor); - console.log(gotoUrl.toString()); goto(gotoUrl); }