From f4a0d3c9734d1662a3f78891f21934f2b82aed1e Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 25 Aug 2026 16:33:03 -0400 Subject: [PATCH] refac --- src/routes/(app)/automations/+page.svelte | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/routes/(app)/automations/+page.svelte b/src/routes/(app)/automations/+page.svelte index 5c3aa8e11f..2b0bfb00e8 100644 --- a/src/routes/(app)/automations/+page.svelte +++ b/src/routes/(app)/automations/+page.svelte @@ -171,19 +171,21 @@ }; const bulkToggleHandler = async (enable: boolean) => { - const targets = (automations ?? []).filter((a) => a.is_active !== enable); - if (targets.length === 0) return; + const allAutomations = await getAllAutomations(query, statusFilter).catch((err) => { + toast.error(`${err}`); + return null; + }); + if (!allAutomations) return; - // Optimistic UI update via map for proper Svelte reactivity - automations = (automations ?? []).map((a) => - targets.some((t) => t.id === a.id) ? { ...a, is_active: enable } : a - ); + const targets = allAutomations.filter((a) => a.is_active !== enable); + if (targets.length === 0) return; try { await Promise.all(targets.map((a) => toggleAutomationById(localStorage.token, a.id))); + if (statusFilter !== 'all') page = 1; + await getAutomationList(); } catch (err) { toast.error(`${err}`); - // Refresh from server to restore consistent state await getAutomationList(); } }; @@ -235,13 +237,13 @@ return automation.folder_id ? $i18n.t('Folder') : $i18n.t('New chat'); }; - const getAllAutomations = async () => { + const getAllAutomations = async (query: string | null = null, status = 'all') => { let currentPage = 1; let allAutomations: AutomationResponse[] = []; let totalAutomations = 0; do { - const res = await getAutomationItems(localStorage.token, null, 'all', currentPage); + const res = await getAutomationItems(localStorage.token, query, status, currentPage); const pageItems = res?.items ?? []; totalAutomations = res?.total ?? pageItems.length; allAutomations = [...allAutomations, ...pageItems];