From dc7385f198696e82ff75d9301518cc7483cee290 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Fri, 15 Nov 2024 17:17:27 -0500 Subject: [PATCH] On each upload, call load from ProcessContext --- src/lib/components/forms/DocumentUpload.svelte | 9 ++++++--- src/lib/components/processing/ProcessContext.svelte | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib/components/forms/DocumentUpload.svelte b/src/lib/components/forms/DocumentUpload.svelte index 494bea961..f351d26a3 100644 --- a/src/lib/components/forms/DocumentUpload.svelte +++ b/src/lib/components/forms/DocumentUpload.svelte @@ -67,7 +67,7 @@ progress through the three-part upload process. isWithinSizeLimit, } from "$lib/utils/files"; import { getCsrfToken } from "$lib/utils/api"; - import { load } from "../processing/ProcessContext.svelte"; + import { getProcessLoader } from "../processing/ProcessContext.svelte"; export let files: File[] = getFilesToUpload(); export let projects: Project[] = []; @@ -85,6 +85,9 @@ progress through the three-part upload process. let STATUS: Record = {}; let loading = false; // are requests in flight? + // Get load function from processing context + const loadProcessing = getProcessLoader(); + // fields let access: Access = "private"; let language: { value: string; label: string } = { @@ -190,8 +193,6 @@ progress through the three-part upload process. form, ), ); - // Try to load processing context after all uploads are triggered - load(); // errors are handled within each promise, so we can just wait for all to be settled await Promise.allSettled(promises); @@ -284,6 +285,8 @@ progress through the three-part upload process. if (error) { STATUS[id].error = error; } + // trigger process load request + loadProcessing?.(); } diff --git a/src/lib/components/processing/ProcessContext.svelte b/src/lib/components/processing/ProcessContext.svelte index c9b535529..ae905548e 100644 --- a/src/lib/components/processing/ProcessContext.svelte +++ b/src/lib/components/processing/ProcessContext.svelte @@ -8,7 +8,7 @@ This makes the state of those processes available via context. import type { Run } from "@/addons/types"; import type { Maybe, Pending } from "@/lib/api/types"; - import { throttle } from "lodash-es"; + import throttle from "lodash-es/throttle"; import { getContext, setContext, @@ -25,6 +25,7 @@ This makes the state of those processes available via context. interface ProcessContext { documents: Writable; addons: Writable; + load: () => void; } interface Debounced { @@ -41,6 +42,10 @@ This makes the state of those processes available via context. return getContext("processing")?.addons; } + export function getProcessLoader(): Maybe<() => void> { + return getContext("processing")?.load; + } + export let addons: Writable = writable([]); export let documents: Writable = writable([]); @@ -65,7 +70,7 @@ This makes the state of those processes available via context.