Skip to content

Commit

Permalink
On each upload, call load from ProcessContext
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Nov 15, 2024
1 parent 09c35f0 commit dc7385f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/lib/components/forms/DocumentUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -85,6 +85,9 @@ progress through the three-part upload process.
let STATUS: Record<string, UploadStatus> = {};
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 } = {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -284,6 +285,8 @@ progress through the three-part upload process.
if (error) {
STATUS[id].error = error;
}
// trigger process load request
loadProcessing?.();
}
</script>

Expand Down
9 changes: 7 additions & 2 deletions src/lib/components/processing/ProcessContext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +25,7 @@ This makes the state of those processes available via context.
interface ProcessContext {
documents: Writable<Pending[]>;
addons: Writable<Run[]>;
load: () => void;
}
interface Debounced {
Expand All @@ -41,6 +42,10 @@ This makes the state of those processes available via context.
return getContext<ProcessContext>("processing")?.addons;
}
export function getProcessLoader(): Maybe<() => void> {
return getContext<ProcessContext>("processing")?.load;
}
export let addons: Writable<Run[]> = writable([]);
export let documents: Writable<Pending[]> = writable([]);
Expand All @@ -65,7 +70,7 @@ This makes the state of those processes available via context.

<script lang="ts">
// stores we need deeper in the component tree, available via context
setContext<ProcessContext>("processing", { addons, documents });
setContext<ProcessContext>("processing", { addons, documents, load });
onMount(() => {
load();
Expand Down

0 comments on commit dc7385f

Please sign in to comment.