fix: disable download button while running jobs, auto run generator jobs

This commit is contained in:
2026-09-12 18:22:05 +05:00
parent 35df076732
commit 0c2de3f191
5 changed files with 44 additions and 54 deletions
+9 -26
View File
@@ -1,32 +1,20 @@
<script lang="ts">
import { Upload } from "@lucide/svelte";
import DownloadButton from "./ui/DownloadButton.svelte";
import { Sparkles, Upload } from "@lucide/svelte";
interface Props {
inputMode: "image" | "text" | "none";
canDownload: boolean;
running: boolean;
onupload: (file: File) => void;
ongenerate: () => void;
ondownload: () => void;
}
let {
inputMode,
canDownload,
running,
onupload,
ongenerate,
ondownload,
}: Props = $props();
let { inputMode, canDownload, running, onupload, ondownload }: Props =
$props();
</script>
<div class="actions">
{#if inputMode === "none"}
<button class="btn generate" onclick={ongenerate} disabled={running}>
<Sparkles size={14} />
{running ? "Generating…" : "Generate"}
</button>
{:else if inputMode === "image"}
{#if inputMode === "image"}
<label class="btn upload">
<Upload size={14} /> Open image
<input
@@ -40,7 +28,11 @@
</label>
{/if}
{#if canDownload}
<DownloadButton label="Download result" onclick={ondownload} />
<DownloadButton
label="Download result"
onclick={ondownload}
disabled={running}
/>
{/if}
</div>
@@ -62,15 +54,6 @@
color: var(--color-text-muted);
cursor: pointer;
}
.generate {
background: var(--color-main);
border-color: var(--color-main);
color: var(--color-background);
}
.generate:disabled {
opacity: 0.6;
cursor: default;
}
.upload input {
display: none;
}
+11 -16
View File
@@ -17,7 +17,6 @@
running?: boolean;
error?: string;
onupload: (file: File) => void;
ongenerate?: () => void;
ontextsource?: (text: string) => void;
onrendertext?: () => void;
oncopytext?: () => void;
@@ -35,7 +34,6 @@
running = false,
error = "",
onupload,
ongenerate,
ontextsource,
onrendertext,
oncopytext,
@@ -43,16 +41,16 @@
ondownload,
}: Props = $props();
const isGenerator = $derived(inputMode === "none");
const sourceValue = $derived(
isGenerator
? "—"
: inputMode === "text"
? "text"
: source
? `${source.width} × ${source.height} px`
: "—",
);
const sourceValue = $derived.by(() => {
switch (inputMode) {
case "none":
return "—";
case "text":
return "text";
case "image":
return source ? `${source.width} × ${source.height} px` : "—";
}
});
const resultValue = $derived(
resultKind === "image"
? result
@@ -77,15 +75,12 @@
</script>
<div class="panel-head">
<span class="label"
>{isGenerator ? "GENERATOR / RESULT" : "SOURCE / RESULT"}</span
>
<span class="label">PREVIEW PANEL</span>
<SchemaActions
{inputMode}
canDownload={hasResult}
{running}
{onupload}
ongenerate={ongenerate ?? (() => {})}
{ondownload}
/>
</div>
+3 -3
View File
@@ -8,12 +8,12 @@
import { execute } from "$lib/executor";
import { t } from "$lib/i18n/t";
import type { FileResult, ToolEntry } from "$lib/registry";
import { downloadZip } from "$lib/zip";
import {
defaultSchemaParams,
sanitizeSchemaParams,
type ToolSchema,
} from "$lib/registry-schema";
import { downloadZip } from "$lib/zip";
interface Props {
tool: ToolEntry;
@@ -142,7 +142,8 @@
});
$effect(() => {
if (inputMode !== "image" || !source || !started) return;
// TODO: can any edge case start infinite loop?
if (!started) return;
void values;
debouncedRun();
return () => debouncedRun.cancel();
@@ -187,7 +188,6 @@
{running}
{error}
onupload={handleFile}
ongenerate={run}
ontextsource={(textValue) => {
textSource = textValue;
}}
@@ -5,8 +5,9 @@
interface Props {
label: string;
onclick?: () => void;
disabled?: boolean;
}
let { label, onclick }: Props = $props();
let { label, onclick, disabled = false }: Props = $props();
</script>
<Button icon={Download} {label} {onclick} />
<Button icon={Download} {label} {onclick} {disabled} />