mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-29 10:09:17 +02:00
refac
This commit is contained in:
@@ -171,19 +171,21 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const bulkToggleHandler = async (enable: boolean) => {
|
const bulkToggleHandler = async (enable: boolean) => {
|
||||||
const targets = (automations ?? []).filter((a) => a.is_active !== enable);
|
const allAutomations = await getAllAutomations(query, statusFilter).catch((err) => {
|
||||||
if (targets.length === 0) return;
|
toast.error(`${err}`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
if (!allAutomations) return;
|
||||||
|
|
||||||
// Optimistic UI update via map for proper Svelte reactivity
|
const targets = allAutomations.filter((a) => a.is_active !== enable);
|
||||||
automations = (automations ?? []).map((a) =>
|
if (targets.length === 0) return;
|
||||||
targets.some((t) => t.id === a.id) ? { ...a, is_active: enable } : a
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(targets.map((a) => toggleAutomationById(localStorage.token, a.id)));
|
await Promise.all(targets.map((a) => toggleAutomationById(localStorage.token, a.id)));
|
||||||
|
if (statusFilter !== 'all') page = 1;
|
||||||
|
await getAutomationList();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error(`${err}`);
|
toast.error(`${err}`);
|
||||||
// Refresh from server to restore consistent state
|
|
||||||
await getAutomationList();
|
await getAutomationList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -235,13 +237,13 @@
|
|||||||
return automation.folder_id ? $i18n.t('Folder') : $i18n.t('New chat');
|
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 currentPage = 1;
|
||||||
let allAutomations: AutomationResponse[] = [];
|
let allAutomations: AutomationResponse[] = [];
|
||||||
let totalAutomations = 0;
|
let totalAutomations = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const res = await getAutomationItems(localStorage.token, null, 'all', currentPage);
|
const res = await getAutomationItems(localStorage.token, query, status, currentPage);
|
||||||
const pageItems = res?.items ?? [];
|
const pageItems = res?.items ?? [];
|
||||||
totalAutomations = res?.total ?? pageItems.length;
|
totalAutomations = res?.total ?? pageItems.length;
|
||||||
allAutomations = [...allAutomations, ...pageItems];
|
allAutomations = [...allAutomations, ...pageItems];
|
||||||
|
|||||||
Reference in New Issue
Block a user