diff --git a/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte b/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte index 358d5eb98..e0b561650 100644 --- a/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte +++ b/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte @@ -34,7 +34,6 @@ return () => sub.unsubscribe(); }); - // Load habits for the select dropdown $effect(() => { const sub = liveQuery(async () => { const all = await db.table('habits').toArray(); @@ -51,7 +50,7 @@ return () => sub.unsubscribe(); }); - // Load suggestions + // ─── Suggestions ───────────────────────────────────────── async function refreshSuggestions() { const all = await generateSuggestions(); suggestions = all.filter((s) => !isSuggestionDismissed(s.id)); @@ -61,9 +60,8 @@ refreshSuggestions(); }); - // Refresh suggestions when automations change $effect(() => { - automations; // track + automations; refreshSuggestions(); }); @@ -121,9 +119,7 @@ async function handleCreate(e: Event) { e.preventDefault(); if (!selectedSource || !selectedAction) return; - const name = newName.trim() || `${selectedSource.appLabel} → ${selectedAction.appLabel}`; - await automationsStore.create({ name, sourceApp: selectedSource.app, @@ -139,239 +135,335 @@ resetForm(); } + // ─── Helpers ───────────────────────────────────────────── function sourceLabel(a: LocalAutomation): string { const src = SOURCE_OPTIONS.find( (s) => s.app === a.sourceApp && s.collection === a.sourceCollection ); - return src - ? `${src.appLabel} / ${src.collectionLabel}` - : `${a.sourceApp}.${a.sourceCollection}`; + return src ? src.appLabel : a.sourceApp; + } + + function sourceDetail(a: LocalAutomation): string { + const src = SOURCE_OPTIONS.find( + (s) => s.app === a.sourceApp && s.collection === a.sourceCollection + ); + const opLabel = a.sourceOp === 'insert' ? 'erstellt' : 'geaendert'; + return src ? `${src.collectionLabel} ${opLabel}` : `${a.sourceCollection} ${opLabel}`; } function actionLabel(a: LocalAutomation): string { const act = ACTION_OPTIONS.find((o) => o.app === a.targetApp && o.action === a.targetAction); - return act ? `${act.appLabel}: ${act.actionLabel}` : `${a.targetApp}.${a.targetAction}`; + return act ? act.appLabel : a.targetApp; + } + + function actionDetail(a: LocalAutomation): string { + const act = ACTION_OPTIONS.find((o) => o.app === a.targetApp && o.action === a.targetAction); + if (!act) return a.targetAction; + if (a.targetAction === 'logHabit' && a.targetParams?.habitId) { + const habit = habits.find((h) => h.id === a.targetParams?.habitId); + return habit ? `${act.actionLabel}: ${habit.title}` : act.actionLabel; + } + return act.actionLabel; } function conditionLabel(a: LocalAutomation): string { - if (!a.conditionField) return 'immer'; + if (!a.conditionField || !a.conditionValue) return ''; const opLabel = CONDITION_OPS.find((o) => o.value === a.conditionOp)?.label ?? a.conditionOp; return `${a.conditionField} ${opLabel} "${a.conditionValue}"`; }