From 28cd950ede6d0fc03e0d7cca0a013d883ea00238 Mon Sep 17 00:00:00 2001 From: Siddharth Kumar Sah Date: Mon, 23 Mar 2026 09:47:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20continuous=20progress=20bar=20(no=20100%?= =?UTF-8?q?=E2=86=920%=20reset)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upload occupies 0-15% of the bar, server processing 15-100%. SSE progress from the server is scaled into the 15-100 range. The bar now moves smoothly from start to finish. --- apps/web/src/hooks/use-tool-processor.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/web/src/hooks/use-tool-processor.ts b/apps/web/src/hooks/use-tool-processor.ts index d5315143..86e51eb1 100644 --- a/apps/web/src/hooks/use-tool-processor.ts +++ b/apps/web/src/hooks/use-tool-processor.ts @@ -97,10 +97,12 @@ export function useToolProcessor(toolId: string) { try { const data = JSON.parse(event.data); if (data.type === "single" && typeof data.percent === "number") { + // Scale server progress (0-100) into 15-100 range + const scaled = 15 + (data.percent / 100) * 85; setProgress((prev) => ({ ...prev, phase: "processing", - percent: data.percent, + percent: scaled, stage: data.stage, })); } @@ -130,9 +132,13 @@ export function useToolProcessor(toolId: string) { const xhr = new XMLHttpRequest(); xhrRef.current = xhr; + // For AI tools: upload = 0-15%, processing = 15-100% (continuous, no reset) + // For fast tools: upload = 0-100%, processing = brief 100% hold + const UPLOAD_WEIGHT = isAiTool ? 15 : 100; + xhr.upload.onprogress = (event) => { if (event.lengthComputable) { - const uploadPercent = (event.loaded / event.total) * 100; + const uploadPercent = (event.loaded / event.total) * UPLOAD_WEIGHT; setProgress((prev) => { if (prev.phase !== "uploading") return prev; return { ...prev, percent: uploadPercent }; @@ -144,7 +150,7 @@ export function useToolProcessor(toolId: string) { setProgress((prev) => ({ ...prev, phase: "processing", - percent: isAiTool ? 0 : 100, + percent: UPLOAD_WEIGHT, stage: isAiTool ? "Starting..." : "Processing...", })); };