Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e46ba09826 | ||
|
|
9550c6ac73 | ||
|
|
ab854593a3 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
Desktop webapp client for [Tern](../) — see [`docs/webapp-client-spec.md`](docs/webapp-client-spec.md) and [`docs/branding-spec.md`](docs/branding-spec.md).
|
||||
|
||||
**Status: read-and-reply mail client** (build order phases 3–4). What's here:
|
||||
**Status: mail client with organisation** (build order phases 3–5). What's here:
|
||||
|
||||
- Vite + Svelte 5 + TypeScript, no other runtime dependencies, per the spec's "fast and simple" priority (§1) and browser-API-only approach (§5).
|
||||
- The decided color palette wired up as CSS custom properties with `data-theme` light/dark/system switching (§4).
|
||||
@@ -13,7 +13,11 @@ Desktop webapp client for [Tern](../) — see [`docs/webapp-client-spec.md`](doc
|
||||
- **Compose, reply and reply-all** in a native `<dialog>`, with drafts. Replying to your own sent message addresses the people you wrote to, not yourself. `Ctrl+Enter` sends.
|
||||
- **Outbox** view for drafts, queued and failed messages, showing retry timing and the last error, with Retry/Delete for failures.
|
||||
- Opening a conversation marks it read.
|
||||
- **Keyboard shortcuts** (§4a): `j`/`k`, `Enter`/`o`, `u`/`Esc`, `g`/`G`, `c`, `r`/`a`, `Shift+R`, `?`. Archive (`e`) is deliberately absent until phase 5 adds the folder semantics behind it — a shortcut that silently does nothing is worse than one that doesn't exist.
|
||||
- **Views, folders and tags** in the sidebar (Inbox, All mail, Sent, Outbox, Trash, your folders, your tags), with tag chips on list rows.
|
||||
- **Conversation actions** — archive, delete/restore, mark read/unread, move, tag — from a toolbar, a right-click context menu (native Popover API, §5), or the keyboard. Keyboard actions apply to the row under the cursor when nothing is open, so mail can be triaged straight from the list.
|
||||
- **Rules editor** — conditions and actions edited as the structured JSON they're stored as, so anything the API accepts the editor can show. Each rule can stop later rules when it matches, and **Run now** applies it to existing mail. Server validation errors (e.g. a bad regex) appear inline without losing the form.
|
||||
- **Trash** shows when each conversation will be permanently deleted.
|
||||
- **Keyboard shortcuts** (§4a): `j`/`k`, `Enter`/`o`, `u`/`Esc`, `g`/`G`, `e` archive, `#` delete/restore, `Shift+I`/`Shift+U` read/unread, `v`/`l` move/tag, `c`, `r`/`a`, `Shift+R`, `?`.
|
||||
- Polls `/events` while the tab is open, since WebSocket push is phase 7.
|
||||
- No PWA, no service worker, no offline cache — matches §2's explicit scope cut.
|
||||
|
||||
@@ -30,7 +34,7 @@ Verified against a message containing a tracking pixel, a remote hero image, a C
|
||||
|
||||
Note the quotes in `img-src 'none'` are load-bearing — unquoted, CSP parses `none` as a *hostname*, which would let `https://none/pixel.gif` through.
|
||||
|
||||
**Not built yet** (later phases): tag/rule management UI, search, attachment download, archive and tagging, WebSocket live updates. Composing is plain text only.
|
||||
**Not built yet** (later phases): search, attachment download, WebSocket live updates. Composing is plain text only.
|
||||
|
||||
## Running
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "tern-web",
|
||||
"version": "0.4.0",
|
||||
"version": "0.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "tern-web",
|
||||
"version": "0.4.0",
|
||||
"version": "0.5.0",
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "tern-web",
|
||||
"private": true,
|
||||
"version": "0.4.0",
|
||||
"version": "0.5.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
<script lang="ts">
|
||||
// One menu for a conversation's actions, used for both the right-click
|
||||
// context menu and the toolbar's "More" button (webapp-client-spec.md
|
||||
// §4a). Native Popover API (§5): light-dismiss and Escape come free.
|
||||
import type { Action, Folder, MailView, Tag, ThreadSummary } from './api';
|
||||
|
||||
let {
|
||||
at,
|
||||
thread,
|
||||
view,
|
||||
folders,
|
||||
tags,
|
||||
onAction,
|
||||
onClose,
|
||||
}: {
|
||||
/** Viewport position to open at; null closes the menu. */
|
||||
at: { x: number; y: number } | null;
|
||||
thread: ThreadSummary | null;
|
||||
view: MailView;
|
||||
folders: Folder[];
|
||||
tags: Tag[];
|
||||
onAction: (actions: Action[]) => void;
|
||||
onClose: () => void;
|
||||
} = $props();
|
||||
|
||||
let menu = $state<HTMLElement | null>(null);
|
||||
|
||||
$effect(() => {
|
||||
if (!menu) return;
|
||||
const open = menu.matches(':popover-open');
|
||||
if (at && !open) {
|
||||
menu.style.left = '0px';
|
||||
menu.style.top = '0px';
|
||||
menu.showPopover();
|
||||
// Measure once shown, then keep the whole menu inside the viewport.
|
||||
const { width, height } = menu.getBoundingClientRect();
|
||||
menu.style.left = `${Math.max(4, Math.min(at.x, innerWidth - width - 4))}px`;
|
||||
menu.style.top = `${Math.max(4, Math.min(at.y, innerHeight - height - 4))}px`;
|
||||
menu.querySelector<HTMLButtonElement>('button')?.focus();
|
||||
} else if (!at && open) {
|
||||
menu.hidePopover();
|
||||
}
|
||||
});
|
||||
|
||||
function pick(actions: Action[]) {
|
||||
// Close through our own path rather than waiting on the popover's
|
||||
// toggle event, which browsers may defer (see Compose.svelte).
|
||||
onAction(actions);
|
||||
onClose();
|
||||
}
|
||||
|
||||
const inTrash = $derived(view.kind === 'trash');
|
||||
const tagged = (id: string) => thread?.tag_ids.includes(id) ?? false;
|
||||
</script>
|
||||
|
||||
<div
|
||||
bind:this={menu}
|
||||
popover="auto"
|
||||
class="menu"
|
||||
role="menu"
|
||||
ontoggle={(e) => { if ((e as ToggleEvent).newState === 'closed') onClose(); }}
|
||||
>
|
||||
{#if thread}
|
||||
{#if inTrash}
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'restore' }])}>Restore</button>
|
||||
{:else}
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'archive' }])}>Archive <kbd>e</kbd></button>
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'delete' }])}>Delete <kbd>#</kbd></button>
|
||||
{/if}
|
||||
{#if thread.unread_count > 0}
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'mark_read' }])}>Mark read <kbd>I</kbd></button>
|
||||
{:else}
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'mark_unread' }])}>Mark unread <kbd>U</kbd></button>
|
||||
{/if}
|
||||
|
||||
<p class="heading">Move to</p>
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'move', folder_id: null }])}>Inbox</button>
|
||||
{#each folders as f (f.id)}
|
||||
<button role="menuitem" onclick={() => pick([{ type: 'move', folder_id: f.id }])}>{f.name}</button>
|
||||
{/each}
|
||||
|
||||
{#if tags.length > 0}
|
||||
<p class="heading">Tags</p>
|
||||
{#each tags as t (t.id)}
|
||||
<button
|
||||
role="menuitemcheckbox"
|
||||
aria-checked={tagged(t.id)}
|
||||
onclick={() => pick([{ type: tagged(t.id) ? 'untag' : 'tag', tag_id: t.id }])}
|
||||
>
|
||||
<span class="dot" style:background={t.color ?? 'var(--primary)'}></span>
|
||||
{t.name}
|
||||
{#if tagged(t.id)}<span class="check">✓</span>{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.menu {
|
||||
position: fixed;
|
||||
margin: 0;
|
||||
inset: auto;
|
||||
min-width: 13rem;
|
||||
max-height: 70vh;
|
||||
overflow-y: auto;
|
||||
padding: 0.3rem;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
|
||||
}
|
||||
button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
padding: 0.35rem 0.6rem;
|
||||
border: none;
|
||||
border-radius: 0.3rem;
|
||||
background: none;
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover,
|
||||
button:focus-visible {
|
||||
background: color-mix(in srgb, var(--secondary) 60%, transparent);
|
||||
outline: none;
|
||||
}
|
||||
.heading {
|
||||
margin: 0.4rem 0.6rem 0.15rem;
|
||||
font-size: 0.7rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--primary);
|
||||
}
|
||||
.dot {
|
||||
width: 0.6rem;
|
||||
height: 0.6rem;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.check {
|
||||
margin-left: auto;
|
||||
color: var(--accent);
|
||||
}
|
||||
kbd {
|
||||
margin-left: auto;
|
||||
font-size: 0.7rem;
|
||||
color: var(--primary);
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.2rem;
|
||||
padding: 0 0.25rem;
|
||||
}
|
||||
</style>
|
||||
+327
-76
@@ -3,21 +3,32 @@
|
||||
// breakpoint (webapp-client-spec.md §4a) — this is a desktop-first app.
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
createFolder,
|
||||
createTag,
|
||||
deleteFolder,
|
||||
deleteTag,
|
||||
listAccounts,
|
||||
listFolders,
|
||||
listOutbox,
|
||||
listTags,
|
||||
listThreads,
|
||||
pollEvents,
|
||||
threadActions,
|
||||
type Account,
|
||||
type Action,
|
||||
type Folder,
|
||||
type MailView,
|
||||
type MessageDetail,
|
||||
type OutboxItem,
|
||||
type Tag,
|
||||
type ThreadSummary,
|
||||
} from './api';
|
||||
import { emptySeed, replySeed, type ComposeSeed } from './reply';
|
||||
import ThreadList from './ThreadList.svelte';
|
||||
import ThreadView from './ThreadView.svelte';
|
||||
import OutboxView from './OutboxView.svelte';
|
||||
import RulesView from './RulesView.svelte';
|
||||
import ActionMenu from './ActionMenu.svelte';
|
||||
import Compose from './Compose.svelte';
|
||||
import ShortcutHelp from './ShortcutHelp.svelte';
|
||||
|
||||
@@ -28,13 +39,15 @@
|
||||
// go out, rather than waiting for the next slow poll.
|
||||
const SEND_WATCH_INTERVAL_MS = 1_500;
|
||||
const SEND_WATCH_LIMIT_MS = 20_000;
|
||||
const TAG_COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#14b8a6', '#64748b'];
|
||||
|
||||
let accounts = $state<Account[]>([]);
|
||||
let folders = $state<Folder[]>([]);
|
||||
let tags = $state<Tag[]>([]);
|
||||
let threads = $state<ThreadSummary[]>([]);
|
||||
let outbox = $state<OutboxItem[]>([]);
|
||||
let view = $state<'mail' | 'outbox'>('mail');
|
||||
let selectedFolderId = $state<string | undefined>(undefined);
|
||||
let section = $state<'mail' | 'outbox' | 'rules'>('mail');
|
||||
let mailView = $state<MailView>({ kind: 'inbox' });
|
||||
let selected = $state<ThreadSummary | null>(null);
|
||||
let threadMessages = $state<MessageDetail[]>([]);
|
||||
let threadReloadKey = $state(0);
|
||||
@@ -43,21 +56,40 @@
|
||||
let error = $state<string | null>(null);
|
||||
let helpOpen = $state(false);
|
||||
let composeSeed = $state<ComposeSeed | null>(null);
|
||||
let menu = $state<{ thread: ThreadSummary; at: { x: number; y: number } } | null>(null);
|
||||
let adding = $state<'folder' | 'tag' | null>(null);
|
||||
let newName = $state('');
|
||||
let eventCursor: string | null = null;
|
||||
|
||||
const ownAddresses = $derived(
|
||||
accounts.flatMap((a) => [a.email_address, a.username]).filter((a): a is string => !!a && a.includes('@')),
|
||||
);
|
||||
const outboxCount = $derived(outbox.length);
|
||||
const viewTitle = $derived.by(() => {
|
||||
switch (mailView.kind) {
|
||||
case 'inbox': return 'Inbox';
|
||||
case 'all': return 'All mail';
|
||||
case 'sent': return 'Sent';
|
||||
case 'trash': return 'Trash';
|
||||
case 'folder': { const id = mailView.id; return folders.find((f) => f.id === id)?.name ?? 'Folder'; }
|
||||
case 'tag': { const id = mailView.id; return tags.find((t) => t.id === id)?.name ?? 'Tag'; }
|
||||
}
|
||||
});
|
||||
|
||||
function isView(v: MailView): boolean {
|
||||
if (section !== 'mail' || v.kind !== mailView.kind) return false;
|
||||
return !('id' in v) || ('id' in mailView && v.id === mailView.id);
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
error = null;
|
||||
try {
|
||||
const page = await listThreads({ folderId: selectedFolderId });
|
||||
const page = await listThreads(mailView);
|
||||
threads = page.threads;
|
||||
if (selected && !threads.some((t) => t.thread_id === selected!.thread_id)) {
|
||||
selected = null;
|
||||
}
|
||||
// Keep the open conversation's summary current (tags, counts), or
|
||||
// drop it if an action moved it out of this view.
|
||||
if (selected) selected = threads.find((t) => t.thread_id === selected!.thread_id) ?? null;
|
||||
activeIndex = Math.min(activeIndex, Math.max(threads.length - 1, 0));
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed to load conversations';
|
||||
} finally {
|
||||
@@ -65,6 +97,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshMeta() {
|
||||
[folders, tags] = await Promise.all([listFolders(), listTags()]);
|
||||
}
|
||||
|
||||
async function refreshOutbox() {
|
||||
try {
|
||||
outbox = await listOutbox();
|
||||
@@ -74,7 +110,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
listFolders().then((f) => (folders = f)).catch(() => {});
|
||||
refreshMeta().catch(() => {});
|
||||
listAccounts().then((a) => (accounts = a)).catch(() => {});
|
||||
refresh();
|
||||
refreshOutbox();
|
||||
@@ -97,9 +133,9 @@
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
|
||||
function selectFolder(id: string | undefined) {
|
||||
view = 'mail';
|
||||
selectedFolderId = id;
|
||||
function showView(v: MailView) {
|
||||
section = 'mail';
|
||||
mailView = v;
|
||||
selected = null;
|
||||
activeIndex = 0;
|
||||
loading = true;
|
||||
@@ -107,7 +143,7 @@
|
||||
}
|
||||
|
||||
function showOutbox() {
|
||||
view = 'outbox';
|
||||
section = 'outbox';
|
||||
selected = null;
|
||||
refreshOutbox();
|
||||
}
|
||||
@@ -123,6 +159,61 @@
|
||||
if (t) t.unread_count = 0;
|
||||
}
|
||||
|
||||
/** The conversation an action applies to: the open one, else the row under the keyboard cursor. */
|
||||
function target(): ThreadSummary | null {
|
||||
return selected ?? threads[activeIndex] ?? null;
|
||||
}
|
||||
|
||||
async function act(thread: ThreadSummary, actions: Action[]) {
|
||||
try {
|
||||
await threadActions(thread.thread_id, actions);
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'action failed';
|
||||
return;
|
||||
}
|
||||
// If the action took the conversation out of this view (archive, move,
|
||||
// delete), go back to the list with the cursor where it was, rather
|
||||
// than auto-opening the next one — opening marks it read.
|
||||
await refresh();
|
||||
threadReloadKey++;
|
||||
}
|
||||
|
||||
function openMenu(thread: ThreadSummary, x: number, y: number) {
|
||||
menu = { thread, at: { x, y } };
|
||||
}
|
||||
|
||||
async function addItem() {
|
||||
const name = newName.trim();
|
||||
if (!name) {
|
||||
adding = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (adding === 'folder') await createFolder(name);
|
||||
else await createTag(name, TAG_COLORS[tags.length % TAG_COLORS.length]);
|
||||
await refreshMeta();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed';
|
||||
}
|
||||
adding = null;
|
||||
newName = '';
|
||||
}
|
||||
|
||||
async function removeFolder(f: Folder) {
|
||||
if (!confirm(`Delete the folder "${f.name}"? Its mail goes back to the inbox.`)) return;
|
||||
await deleteFolder(f.id);
|
||||
if (mailView.kind === 'folder' && mailView.id === f.id) showView({ kind: 'inbox' });
|
||||
await refreshMeta();
|
||||
}
|
||||
|
||||
async function removeTag(t: Tag) {
|
||||
if (!confirm(`Delete the tag "${t.name}"? It's removed from all mail.`)) return;
|
||||
await deleteTag(t.id);
|
||||
if (mailView.kind === 'tag' && mailView.id === t.id) showView({ kind: 'inbox' });
|
||||
await refreshMeta();
|
||||
await refresh();
|
||||
}
|
||||
|
||||
function compose() {
|
||||
composeSeed = emptySeed(accounts.find((a) => a.email_address || a.username.includes('@'))?.id);
|
||||
}
|
||||
@@ -166,18 +257,18 @@
|
||||
threadReloadKey++;
|
||||
}
|
||||
|
||||
// Gmail-style single-key navigation (§4a: treated as core UX, not a
|
||||
// stretch feature). Archive (`e`) is still absent — it needs folder
|
||||
// semantics that arrive with tags and rules.
|
||||
// Gmail-style single-key shortcuts (§4a: core UX, not a stretch feature).
|
||||
// Actions work on the open conversation, or on the row under the cursor
|
||||
// when none is open, so mail can be triaged straight from the list.
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (target && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName))) {
|
||||
return;
|
||||
}
|
||||
const el = event.target as HTMLElement | null;
|
||||
if (el && (el.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName))) return;
|
||||
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
||||
if (composeSeed || helpOpen) return;
|
||||
if (composeSeed || helpOpen || menu) return;
|
||||
|
||||
const newest = threadMessages[threadMessages.length - 1];
|
||||
const t = section === 'mail' ? target() : null;
|
||||
const inTrash = mailView.kind === 'trash';
|
||||
|
||||
switch (event.key) {
|
||||
case 'j':
|
||||
@@ -190,7 +281,7 @@
|
||||
break;
|
||||
case 'Enter':
|
||||
case 'o':
|
||||
if (view === 'mail' && threads[activeIndex]) {
|
||||
if (section === 'mail' && threads[activeIndex]) {
|
||||
event.preventDefault();
|
||||
open(threads[activeIndex], activeIndex);
|
||||
}
|
||||
@@ -219,6 +310,39 @@
|
||||
reply(newest, event.key === 'a');
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
if (t && !inTrash) {
|
||||
event.preventDefault();
|
||||
act(t, [{ type: 'archive' }]);
|
||||
}
|
||||
break;
|
||||
case '#':
|
||||
if (t) {
|
||||
event.preventDefault();
|
||||
act(t, [inTrash ? { type: 'restore' } : { type: 'delete' }]);
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
if (t) {
|
||||
event.preventDefault();
|
||||
act(t, [{ type: 'mark_read' }]);
|
||||
}
|
||||
break;
|
||||
case 'U':
|
||||
if (t) {
|
||||
event.preventDefault();
|
||||
act(t, [{ type: 'mark_unread' }]);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
case 'l': {
|
||||
if (!t) break;
|
||||
event.preventDefault();
|
||||
const row = document.querySelector<HTMLElement>(`[data-index="${activeIndex}"]`);
|
||||
const r = row?.getBoundingClientRect();
|
||||
openMenu(t, r ? r.left + 24 : 200, r ? r.bottom : 120);
|
||||
break;
|
||||
}
|
||||
case 'R':
|
||||
event.preventDefault();
|
||||
refresh();
|
||||
@@ -235,119 +359,242 @@
|
||||
<svelte:window onkeydown={onKeydown} />
|
||||
|
||||
<div class="shell">
|
||||
<nav class="folders" aria-label="Folders">
|
||||
<nav class="sidebar" aria-label="Mailboxes">
|
||||
<button class="compose" onclick={compose}>Compose</button>
|
||||
<button class:active={view === 'mail' && !selectedFolderId} onclick={() => selectFolder(undefined)}>
|
||||
All mail
|
||||
</button>
|
||||
{#each folders as folder (folder.id)}
|
||||
<button
|
||||
class:active={view === 'mail' && selectedFolderId === folder.id}
|
||||
onclick={() => selectFolder(folder.id)}
|
||||
>
|
||||
{folder.name}
|
||||
</button>
|
||||
{/each}
|
||||
<button class:active={view === 'outbox'} onclick={showOutbox}>
|
||||
|
||||
<button class:active={isView({ kind: 'inbox' })} onclick={() => showView({ kind: 'inbox' })}>Inbox</button>
|
||||
<button class:active={isView({ kind: 'all' })} onclick={() => showView({ kind: 'all' })}>All mail</button>
|
||||
<button class:active={isView({ kind: 'sent' })} onclick={() => showView({ kind: 'sent' })}>Sent</button>
|
||||
<button class:active={section === 'outbox'} onclick={showOutbox}>
|
||||
Outbox
|
||||
{#if outboxCount > 0}<span class="badge">{outboxCount}</span>{/if}
|
||||
</button>
|
||||
<button class="help-hint" onclick={() => (helpOpen = true)}>Shortcuts ?</button>
|
||||
<button class:active={isView({ kind: 'trash' })} onclick={() => showView({ kind: 'trash' })}>Trash</button>
|
||||
|
||||
<div class="group">
|
||||
<span>Folders</span>
|
||||
<button class="plus" aria-label="New folder" onclick={() => { adding = 'folder'; newName = ''; }}>+</button>
|
||||
</div>
|
||||
{#each folders as f (f.id)}
|
||||
<div class="item">
|
||||
<button class:active={isView({ kind: 'folder', id: f.id })} onclick={() => showView({ kind: 'folder', id: f.id })}>
|
||||
{f.name}
|
||||
</button>
|
||||
{#if f.role === null}
|
||||
<button class="remove" aria-label={`Delete folder ${f.name}`} onclick={() => removeFolder(f)}>✕</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
{#if adding === 'folder'}
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input class="new" bind:value={newName} placeholder="Folder name" autofocus
|
||||
onkeydown={(e) => { if (e.key === 'Enter') addItem(); if (e.key === 'Escape') adding = null; }}
|
||||
onblur={addItem} />
|
||||
{/if}
|
||||
|
||||
<div class="group">
|
||||
<span>Tags</span>
|
||||
<button class="plus" aria-label="New tag" onclick={() => { adding = 'tag'; newName = ''; }}>+</button>
|
||||
</div>
|
||||
{#each tags as t (t.id)}
|
||||
<div class="item">
|
||||
<button class:active={isView({ kind: 'tag', id: t.id })} onclick={() => showView({ kind: 'tag', id: t.id })}>
|
||||
<span class="dot" style:background={t.color ?? 'var(--primary)'}></span>{t.name}
|
||||
</button>
|
||||
<button class="remove" aria-label={`Delete tag ${t.name}`} onclick={() => removeTag(t)}>✕</button>
|
||||
</div>
|
||||
{/each}
|
||||
{#if adding === 'tag'}
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input class="new" bind:value={newName} placeholder="Tag name" autofocus
|
||||
onkeydown={(e) => { if (e.key === 'Enter') addItem(); if (e.key === 'Escape') adding = null; }}
|
||||
onblur={addItem} />
|
||||
{/if}
|
||||
|
||||
<div class="bottom">
|
||||
<button class:active={section === 'rules'} onclick={() => { section = 'rules'; selected = null; }}>Rules</button>
|
||||
<button class="help-hint" onclick={() => (helpOpen = true)}>Shortcuts ?</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="list-pane">
|
||||
{#if view === 'outbox'}
|
||||
<OutboxView items={outbox} onOpen={openOutboxItem} onChanged={refreshOutbox} />
|
||||
{:else if loading}
|
||||
<p class="note">Loading…</p>
|
||||
{:else if error}
|
||||
<p class="note error">{error}</p>
|
||||
{:else if threads.length === 0}
|
||||
<p class="note">
|
||||
No mail yet. Add an IMAP account and the sync engine will pull the INBOX.
|
||||
</p>
|
||||
{:else}
|
||||
<ThreadList {threads} selectedId={selected?.thread_id ?? null} {activeIndex} onSelect={open} />
|
||||
{/if}
|
||||
</section>
|
||||
{#if section === 'rules'}
|
||||
<section class="wide-pane">
|
||||
<RulesView {folders} {tags} />
|
||||
</section>
|
||||
{:else}
|
||||
<section class="list-pane">
|
||||
{#if section === 'outbox'}
|
||||
<OutboxView items={outbox} onOpen={openOutboxItem} onChanged={refreshOutbox} />
|
||||
{:else}
|
||||
<h2 class="view-title">{viewTitle}</h2>
|
||||
{#if error}<p class="note error">{error}</p>{/if}
|
||||
{#if loading}
|
||||
<p class="note">Loading…</p>
|
||||
{:else if threads.length === 0}
|
||||
<p class="note">
|
||||
{mailView.kind === 'inbox' ? 'Inbox zero.' : 'Nothing here.'}
|
||||
</p>
|
||||
{:else}
|
||||
<ThreadList
|
||||
{threads}
|
||||
{tags}
|
||||
selectedId={selected?.thread_id ?? null}
|
||||
{activeIndex}
|
||||
onSelect={open}
|
||||
onContextMenu={(t, i, x, y) => { activeIndex = i; openMenu(t, x, y); }}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="reading-pane">
|
||||
{#if selected}
|
||||
<ThreadView
|
||||
thread={selected}
|
||||
reloadKey={threadReloadKey}
|
||||
onReply={reply}
|
||||
onLoaded={(m) => (threadMessages = m)}
|
||||
onRead={markedRead}
|
||||
/>
|
||||
{:else}
|
||||
<p class="note">Select a conversation to read it. Press <kbd>?</kbd> for shortcuts.</p>
|
||||
{/if}
|
||||
</section>
|
||||
<section class="reading-pane">
|
||||
{#if selected}
|
||||
<ThreadView
|
||||
thread={selected}
|
||||
view={mailView}
|
||||
reloadKey={threadReloadKey}
|
||||
onReply={reply}
|
||||
onLoaded={(m) => (threadMessages = m)}
|
||||
onRead={markedRead}
|
||||
onAction={(actions) => act(selected!, actions)}
|
||||
onMore={(x, y) => openMenu(selected!, x, y)}
|
||||
/>
|
||||
{:else}
|
||||
<p class="note">Select a conversation to read it. Press <kbd>?</kbd> for shortcuts.</p>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<ActionMenu
|
||||
at={menu?.at ?? null}
|
||||
thread={menu?.thread ?? null}
|
||||
view={mailView}
|
||||
{folders}
|
||||
{tags}
|
||||
onAction={(actions) => menu && act(menu.thread, actions)}
|
||||
onClose={() => (menu = null)}
|
||||
/>
|
||||
<Compose seed={composeSeed} {accounts} onClose={composeClosed} />
|
||||
<ShortcutHelp open={helpOpen} onClose={() => (helpOpen = false)} />
|
||||
|
||||
<style>
|
||||
.shell {
|
||||
display: grid;
|
||||
grid-template-columns: 12rem 22rem 1fr;
|
||||
grid-template-columns: 12.5rem 22rem 1fr;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
.folders {
|
||||
.sidebar {
|
||||
background: color-mix(in srgb, var(--primary) 35%, transparent);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.75rem;
|
||||
gap: 0.25rem;
|
||||
gap: 0.15rem;
|
||||
border-right: 1px solid var(--secondary);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.folders button {
|
||||
.sidebar button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.45rem;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text);
|
||||
padding: 0.45rem 0.7rem;
|
||||
padding: 0.4rem 0.7rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.9rem;
|
||||
font-size: 0.88rem;
|
||||
width: 100%;
|
||||
}
|
||||
.folders button:hover {
|
||||
.sidebar button:hover {
|
||||
background: color-mix(in srgb, var(--secondary) 50%, transparent);
|
||||
}
|
||||
.folders button.active {
|
||||
.sidebar button.active {
|
||||
background: var(--secondary);
|
||||
font-weight: 600;
|
||||
}
|
||||
/* The compose button is one of the few places the accent belongs
|
||||
(branding-spec.md §1). */
|
||||
.folders button.compose {
|
||||
.sidebar button.compose {
|
||||
justify-content: center;
|
||||
background: var(--accent);
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.folders button.compose:hover {
|
||||
background: color-mix(in srgb, var(--accent) 85%, var(--text));
|
||||
}
|
||||
.badge {
|
||||
margin-left: auto;
|
||||
font-size: 0.7rem;
|
||||
padding: 0 0.4rem;
|
||||
border-radius: 0.6rem;
|
||||
background: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
.help-hint {
|
||||
.group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin: 0.7rem 0 0.15rem;
|
||||
padding: 0 0.7rem;
|
||||
font-size: 0.7rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--primary);
|
||||
}
|
||||
.sidebar .group .plus {
|
||||
width: auto;
|
||||
padding: 0 0.35rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.sidebar .item .remove {
|
||||
width: auto;
|
||||
visibility: hidden;
|
||||
padding: 0.2rem 0.4rem;
|
||||
font-size: 0.7rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
/* Hover reveals row actions rather than cluttering every row (§4a). */
|
||||
.item:hover .remove,
|
||||
.item:focus-within .remove {
|
||||
visibility: visible;
|
||||
}
|
||||
.dot {
|
||||
width: 0.55rem;
|
||||
height: 0.55rem;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.new {
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
margin: 0.1rem 0.3rem;
|
||||
padding: 0.3rem 0.45rem;
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 0.3rem;
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
}
|
||||
.bottom {
|
||||
margin-top: auto;
|
||||
padding-top: 0.6rem;
|
||||
}
|
||||
.help-hint {
|
||||
font-size: 0.78rem !important;
|
||||
color: var(--primary) !important;
|
||||
}
|
||||
.view-title {
|
||||
margin: 0;
|
||||
padding: 0.75rem 0.9rem 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
border-bottom: 1px solid var(--secondary);
|
||||
}
|
||||
.list-pane {
|
||||
border-right: 1px solid var(--secondary);
|
||||
display: flex;
|
||||
@@ -359,6 +606,10 @@
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.wide-pane {
|
||||
grid-column: 2 / 4;
|
||||
min-height: 0;
|
||||
}
|
||||
.note {
|
||||
padding: 1rem;
|
||||
color: var(--primary);
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
<script lang="ts">
|
||||
// Edits a rule as the structured JSON it's stored as — one level of
|
||||
// all/any conditions plus an action list — so there's no rule syntax to
|
||||
// parse on either side (server-architecture-spec.md §3.5).
|
||||
import type { Action, Folder, Rule, RuleField, RuleInput, RuleOp, RuleTest, Tag } from './api';
|
||||
|
||||
let {
|
||||
rule,
|
||||
folders,
|
||||
tags,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: {
|
||||
rule: Rule | null;
|
||||
folders: Folder[];
|
||||
tags: Tag[];
|
||||
/** Rejects with the server's validation message, shown inline. */
|
||||
onSave: (input: RuleInput) => Promise<void>;
|
||||
onCancel: () => void;
|
||||
} = $props();
|
||||
|
||||
type ActionType = 'tag' | 'move' | 'archive' | 'mark_read' | 'delete';
|
||||
|
||||
const fields: [RuleField, string][] = [
|
||||
['from', 'From'],
|
||||
['to', 'To'],
|
||||
['cc', 'Cc'],
|
||||
['recipients', 'To or Cc'],
|
||||
['subject', 'Subject'],
|
||||
['body', 'Body'],
|
||||
['header', 'Header…'],
|
||||
];
|
||||
const ops: [RuleOp, string][] = [
|
||||
['contains', 'contains'],
|
||||
['equals', 'is'],
|
||||
['matches', 'matches regex'],
|
||||
['exists', 'exists'],
|
||||
['greater_than', 'is greater than'],
|
||||
['less_than', 'is less than'],
|
||||
];
|
||||
const actionTypes: [ActionType, string][] = [
|
||||
['tag', 'Tag with'],
|
||||
['move', 'Move to'],
|
||||
['archive', 'Archive'],
|
||||
['mark_read', 'Mark read'],
|
||||
['delete', 'Move to Trash'],
|
||||
];
|
||||
|
||||
// The form deliberately snapshots the rule it opened with — edits are
|
||||
// local until saved. RulesView keys this component on the rule, so
|
||||
// opening a different one remounts it rather than reusing stale state.
|
||||
const initial = snapshot();
|
||||
let name = $state(initial.name);
|
||||
let match = $state<'all' | 'any'>(initial.match);
|
||||
let enabled = $state(initial.enabled);
|
||||
let stopAfterMatch = $state(initial.stopAfterMatch);
|
||||
let tests = $state<RuleTest[]>(initial.tests);
|
||||
let actions = $state<{ type: ActionType; target: string }[]>(initial.actions);
|
||||
|
||||
function snapshot() {
|
||||
return {
|
||||
name: rule?.name ?? '',
|
||||
match: rule?.conditions.match ?? ('all' as const),
|
||||
enabled: rule?.enabled ?? true,
|
||||
stopAfterMatch: rule?.stop_after_match ?? false,
|
||||
tests: rule ? rule.conditions.tests.map((t) => ({ ...t, header: t.header ?? '' })) : [blankTest()],
|
||||
actions: rule ? rule.actions.map(toRow) : [{ type: 'tag' as ActionType, target: tags[0]?.id ?? '' }],
|
||||
};
|
||||
}
|
||||
let error = $state<string | null>(null);
|
||||
let saving = $state(false);
|
||||
|
||||
function blankTest(): RuleTest {
|
||||
return { field: 'from', header: '', op: 'contains', value: '', negate: false };
|
||||
}
|
||||
|
||||
function toRow(a: Action): { type: ActionType; target: string } {
|
||||
switch (a.type) {
|
||||
case 'tag':
|
||||
return { type: 'tag', target: a.tag_id };
|
||||
case 'move':
|
||||
return { type: 'move', target: a.folder_id ?? '' };
|
||||
default:
|
||||
return { type: a.type as ActionType, target: '' };
|
||||
}
|
||||
}
|
||||
|
||||
function toAction(row: { type: ActionType; target: string }): Action {
|
||||
switch (row.type) {
|
||||
case 'tag':
|
||||
return { type: 'tag', tag_id: row.target };
|
||||
case 'move':
|
||||
return { type: 'move', folder_id: row.target || null };
|
||||
default:
|
||||
return { type: row.type };
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
error = null;
|
||||
saving = true;
|
||||
try {
|
||||
await onSave({
|
||||
name,
|
||||
enabled,
|
||||
stop_after_match: stopAfterMatch,
|
||||
conditions: {
|
||||
match,
|
||||
tests: tests.map((t) => ({
|
||||
field: t.field,
|
||||
op: t.op,
|
||||
value: t.op === 'exists' ? '' : t.value,
|
||||
negate: t.negate,
|
||||
...(t.field === 'header' ? { header: t.header } : {}),
|
||||
})),
|
||||
},
|
||||
actions: actions.map(toAction),
|
||||
});
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed to save';
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<form class="editor" onsubmit={(e) => { e.preventDefault(); save(); }}>
|
||||
<h2>{rule ? 'Edit rule' : 'New rule'}</h2>
|
||||
|
||||
<label class="name">
|
||||
Name
|
||||
<input bind:value={name} placeholder="e.g. File the weekly newsletter" />
|
||||
</label>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
When
|
||||
<select bind:value={match}>
|
||||
<option value="all">all</option>
|
||||
<option value="any">any</option>
|
||||
</select>
|
||||
of these are true
|
||||
</legend>
|
||||
{#each tests as t, i}
|
||||
<div class="row">
|
||||
<select bind:value={t.field} aria-label="Field">
|
||||
{#each fields as [v, label]}<option value={v}>{label}</option>{/each}
|
||||
</select>
|
||||
{#if t.field === 'header'}
|
||||
<input class="header" bind:value={t.header} placeholder="List-Id" aria-label="Header name" />
|
||||
{/if}
|
||||
<label class="negate"><input type="checkbox" bind:checked={t.negate} /> not</label>
|
||||
<select bind:value={t.op} aria-label="Comparison">
|
||||
{#each ops as [v, label]}<option value={v}>{label}</option>{/each}
|
||||
</select>
|
||||
{#if t.op !== 'exists'}
|
||||
<input class="value" bind:value={t.value} aria-label="Value" />
|
||||
{/if}
|
||||
<button type="button" class="remove" aria-label="Remove condition" onclick={() => tests.splice(i, 1)} disabled={tests.length === 1}>✕</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button type="button" class="add" onclick={() => tests.push(blankTest())}>+ Condition</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>Then</legend>
|
||||
{#each actions as a, i}
|
||||
<div class="row">
|
||||
<select bind:value={a.type} aria-label="Action">
|
||||
{#each actionTypes as [v, label]}<option value={v}>{label}</option>{/each}
|
||||
</select>
|
||||
{#if a.type === 'tag'}
|
||||
<select bind:value={a.target} aria-label="Tag">
|
||||
{#each tags as tag (tag.id)}<option value={tag.id}>{tag.name}</option>{/each}
|
||||
</select>
|
||||
{:else if a.type === 'move'}
|
||||
<select bind:value={a.target} aria-label="Folder">
|
||||
<option value="">Inbox</option>
|
||||
{#each folders as f (f.id)}<option value={f.id}>{f.name}</option>{/each}
|
||||
</select>
|
||||
{/if}
|
||||
<button type="button" class="remove" aria-label="Remove action" onclick={() => actions.splice(i, 1)} disabled={actions.length === 1}>✕</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button type="button" class="add" onclick={() => actions.push({ type: 'archive', target: '' })}>+ Action</button>
|
||||
</fieldset>
|
||||
|
||||
<label class="enabled"><input type="checkbox" bind:checked={enabled} /> Enabled for new mail</label>
|
||||
<label class="enabled">
|
||||
<input type="checkbox" bind:checked={stopAfterMatch} /> Stop — don't run rules below this one when it matches
|
||||
</label>
|
||||
<p class="hint">Rules run on new mail as it arrives, in the order listed. Delete moves mail to Trash, where it can be restored.</p>
|
||||
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
|
||||
<footer>
|
||||
<button type="submit" class="primary" disabled={saving}>{saving ? 'Saving…' : 'Save rule'}</button>
|
||||
<button type="button" onclick={onCancel}>Cancel</button>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 1.25rem;
|
||||
max-width: 52rem;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.name {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
fieldset {
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
padding: 0.6rem 0.8rem 0.8rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
legend {
|
||||
font-size: 0.85rem;
|
||||
padding: 0 0.3rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
input,
|
||||
select {
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text);
|
||||
background: var(--background);
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.3rem;
|
||||
padding: 0.3rem 0.45rem;
|
||||
}
|
||||
input:focus-visible,
|
||||
select:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
.header {
|
||||
width: 9rem;
|
||||
}
|
||||
.value {
|
||||
flex: 1;
|
||||
min-width: 10rem;
|
||||
}
|
||||
.negate,
|
||||
.enabled {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
button {
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text);
|
||||
background: none;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.3rem;
|
||||
padding: 0.3rem 0.7rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: default;
|
||||
}
|
||||
.add {
|
||||
align-self: flex-start;
|
||||
border-style: dashed;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.remove {
|
||||
border: none;
|
||||
color: var(--primary);
|
||||
}
|
||||
.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
footer {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.hint {
|
||||
margin: 0;
|
||||
font-size: 0.78rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.error {
|
||||
margin: 0;
|
||||
color: var(--accent);
|
||||
font-size: 0.85rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,253 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import {
|
||||
createRule,
|
||||
deleteRule,
|
||||
listRules,
|
||||
reorderRules,
|
||||
runRule,
|
||||
updateRule,
|
||||
type Action,
|
||||
type Folder,
|
||||
type Rule,
|
||||
type RuleInput,
|
||||
type Tag,
|
||||
} from './api';
|
||||
import RuleEditor from './RuleEditor.svelte';
|
||||
|
||||
let { folders, tags }: { folders: Folder[]; tags: Tag[] } = $props();
|
||||
|
||||
let rules = $state<Rule[]>([]);
|
||||
let editing = $state<Rule | 'new' | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
/** Per-rule outcome of the last Run now, shown under that rule. */
|
||||
let runResult = $state<Record<string, string>>({});
|
||||
let running = $state<string | null>(null);
|
||||
|
||||
onMount(load);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
rules = await listRules();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed to load rules';
|
||||
}
|
||||
}
|
||||
|
||||
async function save(input: RuleInput) {
|
||||
if (editing === 'new') await createRule(input);
|
||||
else if (editing) await updateRule(editing.id, input);
|
||||
editing = null;
|
||||
await load();
|
||||
}
|
||||
|
||||
async function runNow(rule: Rule) {
|
||||
const what = describeActions(rule.actions);
|
||||
if (!confirm(`Run "${rule.name}" on your existing mail now?\n\nEvery matching message outside Trash will: ${what}.`)) return;
|
||||
running = rule.id;
|
||||
try {
|
||||
const r = await runRule(rule.id);
|
||||
runResult[rule.id] = `Matched ${r.matched} of ${r.scanned} messages.`;
|
||||
} catch (e) {
|
||||
runResult[rule.id] = e instanceof Error ? e.message : 'failed';
|
||||
} finally {
|
||||
running = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(rule: Rule) {
|
||||
await updateRule(rule.id, { ...rule, enabled: !rule.enabled });
|
||||
await load();
|
||||
}
|
||||
|
||||
async function remove(rule: Rule) {
|
||||
if (!confirm(`Delete the rule "${rule.name}"?`)) return;
|
||||
await deleteRule(rule.id);
|
||||
await load();
|
||||
}
|
||||
|
||||
async function move(index: number, by: -1 | 1) {
|
||||
const ids = rules.map((r) => r.id);
|
||||
[ids[index], ids[index + by]] = [ids[index + by], ids[index]];
|
||||
rules = await reorderRules(ids);
|
||||
}
|
||||
|
||||
const fieldLabel: Record<string, string> = {
|
||||
from: 'from', to: 'to', cc: 'cc', recipients: 'to/cc', subject: 'subject', body: 'body',
|
||||
};
|
||||
const opLabel: Record<string, string> = {
|
||||
contains: 'contains', equals: 'is', matches: 'matches', exists: 'exists',
|
||||
greater_than: '>', less_than: '<',
|
||||
};
|
||||
|
||||
function describeActions(actions: Action[]): string {
|
||||
return actions
|
||||
.map((a) => {
|
||||
switch (a.type) {
|
||||
case 'tag': return `tag “${tags.find((t) => t.id === a.tag_id)?.name ?? 'deleted tag'}”`;
|
||||
case 'move': return `move to ${a.folder_id ? (folders.find((f) => f.id === a.folder_id)?.name ?? 'deleted folder') : 'Inbox'}`;
|
||||
case 'archive': return 'archive';
|
||||
case 'mark_read': return 'mark read';
|
||||
case 'delete': return 'move to Trash';
|
||||
default: return a.type;
|
||||
}
|
||||
})
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
function describeTests(rule: Rule): string {
|
||||
const parts = rule.conditions.tests.map((t) => {
|
||||
const field = t.field === 'header' ? (t.header ?? 'header') : fieldLabel[t.field];
|
||||
const value = t.op === 'exists' ? '' : ` “${t.value}”`;
|
||||
return `${field} ${t.negate ? 'not ' : ''}${opLabel[t.op]}${value}`;
|
||||
});
|
||||
return parts.join(rule.conditions.match === 'all' ? ' and ' : ' or ');
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="rules">
|
||||
{#if editing}
|
||||
{#key editing}
|
||||
<RuleEditor
|
||||
rule={editing === 'new' ? null : editing}
|
||||
{folders}
|
||||
{tags}
|
||||
onSave={save}
|
||||
onCancel={() => (editing = null)}
|
||||
/>
|
||||
{/key}
|
||||
{:else}
|
||||
<header>
|
||||
<h2>Rules</h2>
|
||||
<button class="primary" onclick={() => (editing = 'new')}>New rule</button>
|
||||
</header>
|
||||
<p class="hint">
|
||||
Applied to new mail in this order; every matching rule runs unless one above it is set to stop. Run now applies a single rule to mail you already have — disabled rules included, so you can try one before switching it on.
|
||||
</p>
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
{#if rules.length === 0}
|
||||
<p class="empty">No rules yet.</p>
|
||||
{/if}
|
||||
<ol>
|
||||
{#each rules as rule, i (rule.id)}
|
||||
<li class:disabled={!rule.enabled}>
|
||||
<div class="order">
|
||||
<button aria-label="Move up" disabled={i === 0} onclick={() => move(i, -1)}>▲</button>
|
||||
<button aria-label="Move down" disabled={i === rules.length - 1} onclick={() => move(i, 1)}>▼</button>
|
||||
</div>
|
||||
<div class="body">
|
||||
<strong>{rule.name}</strong>
|
||||
<span class="summary">
|
||||
If {describeTests(rule)} → {describeActions(rule.actions)}{rule.stop_after_match ? ', then stop' : ''}
|
||||
</span>
|
||||
{#if runResult[rule.id]}<span class="result">{runResult[rule.id]}</span>{/if}
|
||||
</div>
|
||||
<label class="toggle"><input type="checkbox" checked={rule.enabled} onchange={() => toggle(rule)} /> on</label>
|
||||
<button onclick={() => runNow(rule)} disabled={running !== null} title="Apply to existing mail">
|
||||
{running === rule.id ? 'Running…' : 'Run now'}
|
||||
</button>
|
||||
<button onclick={() => (editing = rule)}>Edit</button>
|
||||
<button onclick={() => remove(rule)}>Delete</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.rules {
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
}
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 1.25rem 1.25rem 0;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.hint,
|
||||
.empty,
|
||||
.error {
|
||||
padding: 0 1.25rem;
|
||||
font-size: 0.82rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.error {
|
||||
color: var(--accent);
|
||||
}
|
||||
ol {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 1.25rem 1.25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
}
|
||||
/* Dim the description only: Run now still works on a disabled rule, so
|
||||
its buttons mustn't look disabled too. */
|
||||
li.disabled .body {
|
||||
opacity: 0.55;
|
||||
}
|
||||
.order {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.order button {
|
||||
border: none;
|
||||
padding: 0 0.2rem;
|
||||
font-size: 0.6rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
.summary {
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.result {
|
||||
font-size: 0.78rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
.toggle {
|
||||
font-size: 0.8rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
button {
|
||||
font: inherit;
|
||||
font-size: 0.82rem;
|
||||
color: var(--text);
|
||||
background: none;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.3rem;
|
||||
padding: 0.25rem 0.6rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: default;
|
||||
}
|
||||
.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@@ -16,6 +16,10 @@
|
||||
['Enter or o', 'Open conversation'],
|
||||
['u or Esc', 'Back to list'],
|
||||
['g / G', 'Jump to first / last'],
|
||||
['e', 'Archive'],
|
||||
['#', 'Delete (restore, in Trash)'],
|
||||
['Shift+I / Shift+U', 'Mark read / unread'],
|
||||
['v or l', 'Move or tag'],
|
||||
['c', 'Compose'],
|
||||
['r / a', 'Reply / reply all to the open conversation'],
|
||||
['Ctrl+Enter', 'Send (while composing)'],
|
||||
@@ -33,7 +37,8 @@
|
||||
{/each}
|
||||
</dl>
|
||||
<p class="note">
|
||||
Archive and tag shortcuts arrive with the phase that adds tags and rules.
|
||||
Actions apply to the open conversation, or to the one under the cursor when none is open.
|
||||
Right-click a conversation for the same menu.
|
||||
</p>
|
||||
<button onclick={onClose}>Close</button>
|
||||
</dialog>
|
||||
|
||||
@@ -1,19 +1,31 @@
|
||||
<script lang="ts">
|
||||
import type { ThreadSummary } from './api';
|
||||
import type { Tag, ThreadSummary } from './api';
|
||||
import { formatListDate } from './format';
|
||||
|
||||
let {
|
||||
threads,
|
||||
selectedId,
|
||||
activeIndex,
|
||||
tags,
|
||||
onSelect,
|
||||
onContextMenu,
|
||||
}: {
|
||||
threads: ThreadSummary[];
|
||||
selectedId: string | null;
|
||||
activeIndex: number;
|
||||
tags: Tag[];
|
||||
onSelect: (thread: ThreadSummary, index: number) => void;
|
||||
/** Right-click on a row (§4a: context menus instead of a "…" per row). */
|
||||
onContextMenu: (thread: ThreadSummary, index: number, x: number, y: number) => void;
|
||||
} = $props();
|
||||
|
||||
const tagById = $derived(new Map(tags.map((t) => [t.id, t])));
|
||||
|
||||
function purgeText(at: string): string {
|
||||
const days = Math.ceil((new Date(at).getTime() - Date.now()) / 86_400_000);
|
||||
return days <= 0 ? 'Deleted permanently soon' : `Deleted permanently in ${days} day${days === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
let listEl = $state<HTMLElement | null>(null);
|
||||
|
||||
// Keep the keyboard cursor visible when j/k walks past the viewport edge.
|
||||
@@ -34,6 +46,10 @@
|
||||
role="option"
|
||||
aria-selected={thread.thread_id === selectedId}
|
||||
onclick={() => onSelect(thread, i)}
|
||||
oncontextmenu={(e) => {
|
||||
e.preventDefault();
|
||||
onContextMenu(thread, i, e.clientX, e.clientY);
|
||||
}}
|
||||
>
|
||||
<span class="top">
|
||||
<span class="from">{thread.last_from || 'Unknown sender'}</span>
|
||||
@@ -48,6 +64,19 @@
|
||||
<span class="attach" aria-label="Has attachments">📎</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if thread.purges_at}
|
||||
<span class="purge">{purgeText(thread.purges_at)}</span>
|
||||
{/if}
|
||||
{#if thread.tag_ids.length > 0}
|
||||
<span class="chips">
|
||||
{#each thread.tag_ids as id (id)}
|
||||
{@const tag = tagById.get(id)}
|
||||
{#if tag}
|
||||
<span class="chip" style:--chip={tag.color ?? 'var(--primary)'}>{tag.name}</span>
|
||||
{/if}
|
||||
{/each}
|
||||
</span>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -127,4 +156,21 @@
|
||||
.attach {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.purge {
|
||||
font-size: 0.72rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
.chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.chip {
|
||||
font-size: 0.68rem;
|
||||
padding: 0 0.4rem;
|
||||
border-radius: 0.6rem;
|
||||
border: 1px solid var(--chip);
|
||||
background: color-mix(in srgb, var(--chip) 18%, transparent);
|
||||
color: var(--text);
|
||||
}
|
||||
</style>
|
||||
@@ -1,16 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { getThread, markThreadRead, type MessageDetail, type ThreadSummary } from './api';
|
||||
import {
|
||||
getThread,
|
||||
markThreadRead,
|
||||
type Action,
|
||||
type MailView,
|
||||
type MessageDetail,
|
||||
type ThreadSummary,
|
||||
} from './api';
|
||||
import { formatFullDate } from './format';
|
||||
import MessageBody from './MessageBody.svelte';
|
||||
|
||||
let {
|
||||
thread,
|
||||
view,
|
||||
reloadKey = 0,
|
||||
onReply,
|
||||
onLoaded,
|
||||
onRead,
|
||||
onAction,
|
||||
onMore,
|
||||
}: {
|
||||
thread: ThreadSummary;
|
||||
view: MailView;
|
||||
onAction: (actions: Action[]) => void;
|
||||
/** Opens the full action menu (move, tags) at a viewport position. */
|
||||
onMore: (x: number, y: number) => void;
|
||||
/** Bumped by the parent to refetch, e.g. after a reply is sent. */
|
||||
reloadKey?: number;
|
||||
onReply: (message: MessageDetail, all: boolean) => void;
|
||||
@@ -19,7 +33,13 @@
|
||||
onRead?: (threadId: string) => void;
|
||||
} = $props();
|
||||
|
||||
let messages = $state<MessageDetail[]>([]);
|
||||
let loaded = $state<MessageDetail[]>([]);
|
||||
// A rule may have trashed one message of a thread; outside Trash it's
|
||||
// hidden, in Trash only the trashed ones show.
|
||||
const messages = $derived(
|
||||
loaded.filter((m) => (view.kind === 'trash') === (m.deleted_at !== null)),
|
||||
);
|
||||
const inTrash = $derived(view.kind === 'trash');
|
||||
let loading = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
@@ -36,12 +56,12 @@
|
||||
imagesAllowed = {};
|
||||
getThread(id)
|
||||
.then((result) => {
|
||||
messages = result;
|
||||
loaded = result;
|
||||
// Collapse all but the newest, the one most likely to be read.
|
||||
expanded = Object.fromEntries(
|
||||
result.map((m, i) => [m.id, i === result.length - 1]),
|
||||
);
|
||||
onLoaded?.(result);
|
||||
onLoaded?.(messages);
|
||||
// Opening a conversation reads it. Only bother the server when
|
||||
// something is actually unread.
|
||||
if (thread.unread_count > 0) {
|
||||
@@ -63,6 +83,22 @@
|
||||
</script>
|
||||
|
||||
<article class="thread">
|
||||
<div class="toolbar" role="toolbar" aria-label="Conversation actions">
|
||||
{#if inTrash}
|
||||
<button onclick={() => onAction([{ type: 'restore' }])}>Restore</button>
|
||||
{:else}
|
||||
<button onclick={() => onAction([{ type: 'archive' }])} title="Archive (e)">Archive</button>
|
||||
<button onclick={() => onAction([{ type: 'delete' }])} title="Delete (#)">Delete</button>
|
||||
{/if}
|
||||
<button onclick={() => onAction([{ type: 'mark_unread' }])} title="Mark unread (Shift+U)">Mark unread</button>
|
||||
<button
|
||||
onclick={(e) => {
|
||||
const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
||||
onMore(r.left, r.bottom + 4);
|
||||
}}
|
||||
title="Move or tag (v / l)"
|
||||
>Move / Tag ▾</button>
|
||||
</div>
|
||||
<header>
|
||||
<h1>{thread.subject || '(no subject)'}</h1>
|
||||
<p class="count">{count} {count === 1 ? 'message' : 'messages'}</p>
|
||||
@@ -115,6 +151,25 @@
|
||||
</article>
|
||||
|
||||
<style>
|
||||
.toolbar {
|
||||
display: flex;
|
||||
gap: 0.35rem;
|
||||
padding-bottom: 0.25rem;
|
||||
border-bottom: 1px solid var(--secondary);
|
||||
}
|
||||
.toolbar button {
|
||||
font: inherit;
|
||||
font-size: 0.8rem;
|
||||
border: 1px solid var(--secondary);
|
||||
background: none;
|
||||
color: var(--text);
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.25rem 0.7rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.toolbar button:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.thread {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
+112
-7
@@ -36,6 +36,8 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
export interface Folder {
|
||||
id: string;
|
||||
name: string;
|
||||
/** 'archive' for the system Archive folder, null for the user's own. */
|
||||
role: 'archive' | null;
|
||||
}
|
||||
|
||||
export interface MessageSummary {
|
||||
@@ -50,6 +52,7 @@ export interface MessageSummary {
|
||||
flags: string[];
|
||||
/** 'imap' for received mail, 'sent' for mail sent from Tern. */
|
||||
source: 'imap' | 'sent';
|
||||
deleted_at: string | null;
|
||||
}
|
||||
|
||||
export interface MessageBody {
|
||||
@@ -71,6 +74,9 @@ export interface ThreadSummary {
|
||||
message_count: number;
|
||||
unread_count: number;
|
||||
has_attachments: boolean;
|
||||
tag_ids: string[];
|
||||
/** In Trash: when this conversation is deleted for good. */
|
||||
purges_at: string | null;
|
||||
}
|
||||
|
||||
/** Flags are stored in IMAP wire format, so unread is the absence of \Seen. */
|
||||
@@ -82,15 +88,24 @@ export function listFolders(): Promise<Folder[]> {
|
||||
return request('/folders');
|
||||
}
|
||||
|
||||
export function listThreads(params: { folderId?: string; before?: string } = {}): Promise<{
|
||||
/** Which slice of the mailbox a thread list shows. */
|
||||
export type MailView =
|
||||
| { kind: 'inbox' }
|
||||
| { kind: 'all' }
|
||||
| { kind: 'sent' }
|
||||
| { kind: 'trash' }
|
||||
| { kind: 'folder'; id: string }
|
||||
| { kind: 'tag'; id: string };
|
||||
|
||||
export function listThreads(view: MailView, before?: string): Promise<{
|
||||
threads: ThreadSummary[];
|
||||
next_cursor: string | null;
|
||||
}> {
|
||||
const query = new URLSearchParams();
|
||||
if (params.folderId) query.set('folder_id', params.folderId);
|
||||
if (params.before) query.set('before', params.before);
|
||||
const qs = query.toString();
|
||||
return request(`/threads${qs ? `?${qs}` : ''}`);
|
||||
const query = new URLSearchParams({ view: view.kind });
|
||||
if (view.kind === 'folder') query.set('folder_id', view.id);
|
||||
if (view.kind === 'tag') query.set('tag_id', view.id);
|
||||
if (before) query.set('before', before);
|
||||
return request(`/threads?${query}`);
|
||||
}
|
||||
|
||||
export function getThread(threadId: string): Promise<MessageDetail[]> {
|
||||
@@ -154,7 +169,7 @@ export function listAccounts(): Promise<Account[]> {
|
||||
return request('/accounts');
|
||||
}
|
||||
|
||||
export function markThreadRead(threadId: string): Promise<{ updated: number }> {
|
||||
export function markThreadRead(threadId: string): Promise<{ messages: number }> {
|
||||
return request(`/threads/${threadId}/read`, { method: 'POST' });
|
||||
}
|
||||
|
||||
@@ -183,3 +198,93 @@ export function sendOutboxItem(id: string): Promise<OutboxItem> {
|
||||
export function deleteOutboxItem(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/outbox/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
id: string;
|
||||
name: string;
|
||||
color: string | null;
|
||||
}
|
||||
|
||||
/** Same shape as rule actions — manual actions and rules share one applier. */
|
||||
export type Action =
|
||||
| { type: 'tag'; tag_id: string }
|
||||
| { type: 'untag'; tag_id: string }
|
||||
| { type: 'move'; folder_id: string | null }
|
||||
| { type: 'archive' }
|
||||
| { type: 'mark_read' }
|
||||
| { type: 'mark_unread' }
|
||||
| { type: 'delete' }
|
||||
| { type: 'restore' };
|
||||
|
||||
export type RuleField = 'from' | 'to' | 'cc' | 'recipients' | 'subject' | 'body' | 'header';
|
||||
export type RuleOp = 'contains' | 'equals' | 'matches' | 'exists' | 'greater_than' | 'less_than';
|
||||
|
||||
export interface RuleTest {
|
||||
field: RuleField;
|
||||
header?: string;
|
||||
op: RuleOp;
|
||||
value: string;
|
||||
negate: boolean;
|
||||
}
|
||||
|
||||
export interface Rule {
|
||||
id: string;
|
||||
name: string;
|
||||
conditions: { match: 'all' | 'any'; tests: RuleTest[] };
|
||||
actions: Action[];
|
||||
enabled: boolean;
|
||||
/** Skip lower-priority rules once this one matches. */
|
||||
stop_after_match: boolean;
|
||||
priority: number;
|
||||
}
|
||||
|
||||
export type RuleInput = Omit<Rule, 'id' | 'priority'>;
|
||||
|
||||
export function threadActions(threadId: string, actions: Action[]): Promise<{ messages: number }> {
|
||||
return request(`/threads/${threadId}/actions`, { method: 'POST', body: JSON.stringify({ actions }) });
|
||||
}
|
||||
|
||||
export function listTags(): Promise<Tag[]> {
|
||||
return request('/tags');
|
||||
}
|
||||
|
||||
export function createTag(name: string, color: string | null): Promise<Tag> {
|
||||
return request('/tags', { method: 'POST', body: JSON.stringify({ name, color }) });
|
||||
}
|
||||
|
||||
export function deleteTag(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/tags/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function createFolder(name: string): Promise<Folder> {
|
||||
return request('/folders', { method: 'POST', body: JSON.stringify({ name }) });
|
||||
}
|
||||
|
||||
export function deleteFolder(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/folders/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function listRules(): Promise<Rule[]> {
|
||||
return request('/rules');
|
||||
}
|
||||
|
||||
export function createRule(rule: RuleInput): Promise<Rule> {
|
||||
return request('/rules', { method: 'POST', body: JSON.stringify(rule) });
|
||||
}
|
||||
|
||||
export function updateRule(id: string, rule: RuleInput): Promise<Rule> {
|
||||
return request(`/rules/${id}`, { method: 'PUT', body: JSON.stringify(rule) });
|
||||
}
|
||||
|
||||
export function deleteRule(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/rules/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/** Applies a rule to existing mail — what "Run now" does. */
|
||||
export function runRule(id: string): Promise<{ scanned: number; matched: number }> {
|
||||
return request(`/rules/${id}/run`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function reorderRules(ids: string[]): Promise<Rule[]> {
|
||||
return request('/rules/reorder', { method: 'POST', body: JSON.stringify({ ids }) });
|
||||
}
|
||||
Reference in new issue
Block a user