From f5cabe6eed4f2e533d450aad02ac18cee13ccbf4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 21 Nov 2026 18:45:34 +0400 Subject: [PATCH] refac --- .../automations/AutomationEditor.svelte | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/lib/components/automations/AutomationEditor.svelte b/src/lib/components/automations/AutomationEditor.svelte index 109dace32c..970c55b066 100644 --- a/src/lib/components/automations/AutomationEditor.svelte +++ b/src/lib/components/automations/AutomationEditor.svelte @@ -80,6 +80,23 @@ let prompt = ''; // Like the model editor's system prompt: a saved prompt starts collapsed. let showPrompt = true; + // Collapsing (and its Show more / Show less toggle) only applies when the prompt is longer + // than the five-line preview; a hidden copy of the preview tells us whether it gets cut off. + let promptMeasureEl: HTMLDivElement | null = null; + let promptClamped = false; + const measurePrompt = () => { + if (!promptMeasureEl) return; + promptClamped = promptMeasureEl.scrollHeight > promptMeasureEl.clientHeight + 1; + }; + $: if (promptMeasureEl) { + void prompt; + tick().then(measurePrompt); + } + onMount(() => { + const observer = new ResizeObserver(measurePrompt); + if (promptMeasureEl) observer.observe(promptMeasureEl); + return () => observer.disconnect(); + }); let model_id = ''; let folder_id = ''; let target_type: 'chat' | 'channel' = 'chat'; @@ -341,10 +358,9 @@ const request = loadMore ? runsRequest : ++runsRequest; runsLoading = true; - if (!loadMore) { - runsPage = 0; - hasMoreRuns = true; - } + // hasMoreRuns keeps its value until the response arrives, so the "Automation created" + // row doesn't blink out on every reload. + if (!loadMore) runsPage = 0; try { const fetchedRuns = @@ -352,16 +368,21 @@ localStorage.token, automation.id, runsPage * RUNS_PAGE_SIZE, - RUNS_PAGE_SIZE, + // One extra row tells us whether another page exists without an empty "Show more". + RUNS_PAGE_SIZE + 1, runsDirection )) ?? []; if (request !== runsRequest) return; - runs = loadMore ? [...runs, ...fetchedRuns] : fetchedRuns; - hasMoreRuns = fetchedRuns.length === RUNS_PAGE_SIZE; + const pageRuns = fetchedRuns.slice(0, RUNS_PAGE_SIZE); + runs = loadMore ? [...runs, ...pageRuns] : pageRuns; + hasMoreRuns = fetchedRuns.length > RUNS_PAGE_SIZE; runsPage++; } catch { if (request !== runsRequest) return; - if (!loadMore) runs = []; + if (!loadMore) { + runs = []; + hasMoreRuns = false; + } } runsLoading = false; }; @@ -458,7 +479,16 @@ deleteHandler={() => (showDeleteConfirm = true)} /> - {#if showPrompt || !prompt.trim()} +
+ +
+ {#if showPrompt || !promptClamped}