Initial webapp scaffold
Vite + Svelte 5 + TypeScript with no other runtime dependencies, per the client spec's speed-and-simplicity priority. Wires up the decided palette with light/dark/system switching, a two-pane desktop shell, and a thin API client against the sync server. Deliberately no PWA/service worker, matching the spec's scope cut. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
commit
1145e31af6
19 files changed
+2203
No files matched your search
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
.env
|
||||
*.log
|
||||
.DS_Store
|
||||
@@ -0,0 +1,23 @@
|
||||
# tern-web
|
||||
|
||||
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: thin scaffold.** This is a minimal placeholder, not a built-out feature set — the server side (IMAP sync + REST API) was the priority for this first pass. 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).
|
||||
- A two-pane shell (folder list / message list / reading pane) that calls the real `tern-server` REST API for folders and messages, plus a login form against `/api/auth/login`.
|
||||
- No PWA, no service worker, no offline cache — matches §2's explicit scope cut.
|
||||
|
||||
**Not built yet** (left for later passes, matching the server's `docs/server-architecture-spec.md` §9 build order): compose/reply, tag/rule management UI, search, keyboard shortcuts (§4a/§9 open item), sandboxed HTML mail rendering (§6), WebSocket live updates (falls back to nothing right now — no polling loop wired up either).
|
||||
|
||||
## Running
|
||||
|
||||
Requires `tern-server` running on `127.0.0.1:8080` (see [`../server/README.md`](../server/README.md)) — the dev server proxies `/api` to it.
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
`npm run check` runs `svelte-check` for type errors.
|
||||
@@ -0,0 +1,80 @@
|
||||
# Tern — Branding Doc
|
||||
|
||||
Name decided: **Tern**. This doc covers default color palette and icon direction; the naming shortlist that led here is kept in §4 for reference.
|
||||
|
||||
Ties into the theming decisions in the Android and webapp design docs (Android: dynamic color where available, static fallback otherwise; webapp: static palette only, decided).
|
||||
|
||||
---
|
||||
|
||||
## 1. Default Color Palette — Decided
|
||||
|
||||
Palette is set (exported from a color design tool, values below are the ones that matter — treat the original export's other syntax as noise):
|
||||
|
||||
```css
|
||||
:root[data-theme="light"] {
|
||||
--text: #0c0a10;
|
||||
--background: #f4f3f7;
|
||||
--primary: #988fa8;
|
||||
--secondary: #c3c7d5;
|
||||
--accent: #f39a39;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--text: #f1eff5;
|
||||
--background: #09080c;
|
||||
--primary: #605770;
|
||||
--secondary: #2a2e3c;
|
||||
--accent: #c66c0c;
|
||||
}
|
||||
```
|
||||
|
||||
Reads as a muted violet-grey primary/secondary pair with a warm orange accent — matches the "calm, not loud" direction from the original brief well, and the orange accent avoids the sea-of-blue-mail-icons problem noted below (§2).
|
||||
|
||||
**Where each token is used, roughly:**
|
||||
- `--text` / `--background`: base page text and surface.
|
||||
- `--primary`: the app's dominant UI color — nav/sidebar surfaces, primary buttons, selected states.
|
||||
- `--secondary`: secondary surfaces — borders, dividers, unselected/inactive UI, hover backgrounds.
|
||||
- `--accent`: sparingly, for things that need to stand out from the calm primary/secondary — unread indicators, the compose button, notification badges, links.
|
||||
|
||||
**Applies to both clients:**
|
||||
- **Webapp**: this is the actual palette, consumed directly as CSS custom properties (see the webapp design doc, §4) — no generation step needed, it's already final.
|
||||
- **Android**: use this as the **static fallback palette** (API <12, or dynamic color disabled) — derive a Material 3-compatible tonal scheme from these five colors (e.g. via Material Theme Builder, feeding `--accent` in as the seed) rather than hand-placing them into Compose's color roles one at a time, so you get correctly-contrasted tonal variants (hover/pressed/disabled states, surface elevation) rather than just the five raw values. When dynamic color *is* active, the system wallpaper palette takes over as designed — this fallback only matters when it isn't available.
|
||||
|
||||
**Neutral/surface colors**: `--background`/`--secondary` already cover the two ends of a light/dark neutral scale; if more granular surface elevation levels are needed (e.g. Material 3's surface-container tiers on Android), interpolate between them rather than introducing new unrelated greys.
|
||||
|
||||
---
|
||||
|
||||
## 2. Icon Direction
|
||||
|
||||
- **Keep it a single, simple mark** — one shape, one or two colors max, works down to a 24×24 favicon and up to a 512×512 store listing without needing different detail levels.
|
||||
- **Avoid an envelope glyph** — it's the single most overused email-app icon shape (Gmail, Outlook, Apple Mail, Thunderbird, Spark, and dozens of others all use envelope variants), so it's the hardest shape to make distinctive and the easiest to blend into a phone's homescreen. With "Tern" as the name, there's a natural way out of this anyway (below).
|
||||
- **Bird mark, tied to the name**: a simple geometric tern silhouette — a forked-tail, in-flight wing shape reads clearly at small sizes and is fairly distinctive as a category (most mail-app icons are envelopes or abstract blobs, not birds). Keep it abstracted/geometric rather than a literal illustrated bird — a few clean angular strokes, not feather detail — so it holds up at 16×16 and doesn't read as twee at 512×512.
|
||||
- Alternative if the literal bird ends up feeling too cute in practice: a single wing/chevron shape alone (implying flight/motion without being a full bird), using the `--accent` orange (§1) so the icon and app color are inherently linked.
|
||||
|
||||
**Required export set** (ties to both client docs):
|
||||
- 192×192 and 512×512 standard icons (webapp manifest)
|
||||
- A **maskable** variant (safe-zone padding so it isn't clipped when the OS applies its own mask shape) for both Android and PWA install
|
||||
- A **monochrome/themed** variant (single-color silhouette, API 33+) so the Android launcher icon can tint to the system's dynamic color instead of showing your static brand color on every homescreen
|
||||
- Standard favicon sizes (16×16, 32×32) generated down from the same master mark, not redrawn separately
|
||||
|
||||
---
|
||||
|
||||
## 3. Open Items for Later
|
||||
|
||||
- **Do a real trademark/domain search for "Tern"** before treating the name as final — the check that led here (§4) was a quick sanity pass, not a clearance search.
|
||||
- Wordmark/typeface pairing for "Tern" — not addressed here, worth a short follow-up now that naming is settled.
|
||||
- Whether the icon mark shows up anywhere in the webapp UI itself (e.g. empty states, loading screens) or stays purely an app-icon/favicon asset.
|
||||
|
||||
---
|
||||
|
||||
## 4. Naming Shortlist (reference — decision already made, kept for context)
|
||||
|
||||
Other directions considered before settling on **Tern**, in case any of these end up useful later (a product line name, a subdomain, etc.). Worth knowing up front: **Postbox**, **Thunderbird**, **K-9 Mail**, **Dove**, **Spark**, **Mailbird**, **BlueMail** are all existing, actively-used email client names that were avoided.
|
||||
|
||||
- **Nook** — evokes a small, quiet, personal space rather than a busy inbox.
|
||||
- **Fen** — short, calm, slightly unusual, memorable as a wordmark.
|
||||
- **Quire** — old word for a set of folded pages (paper/letters association) without being on-the-nose "mail."
|
||||
- **Parcel** — evokes something arriving, distinct from "inbox"/"mail" clichés. (Also used by an unrelated JS build-tool project — fine for an unrelated category, but worth knowing.)
|
||||
- **Envoy** — "the thing that carries the message."
|
||||
- **Petrel** — same bird family as Tern, if a different specific bird ever appealed more.
|
||||
- **Fetch** — plain, references the IMAP-fetch mechanic directly.
|
||||
- **Relay** — technically accurate (it relays between IMAP and you), clean word, easy to pronounce in multiple languages.
|
||||
@@ -0,0 +1,115 @@
|
||||
# Tern — Webapp Client Design Doc
|
||||
|
||||
Companion to the server architecture spec and Android client design doc.
|
||||
|
||||
---
|
||||
|
||||
## 1. Philosophy
|
||||
|
||||
**Fast and simple over feature-complete.** The explicit priority order: speed and simplicity first, functionality second. Avoid becoming a "does everything" app — every feature added should justify its cost in complexity and page weight.
|
||||
|
||||
**Target: desktop, Chrome + Firefox.** Unlike the Android client, this isn't a touch/mobile-first design — it's built for a mouse-and-keyboard desktop session in current Chrome or Firefox. That changes several defaults from a typical "mobile-first PWA" doc (see §4).
|
||||
|
||||
Practical implications:
|
||||
- Prefer a lightweight framework (or none) over a heavy SPA framework with a large runtime. Whatever's chosen, keep the shipped JS bundle small and avoid pulling in a large component library for things that can be a few lines of CSS.
|
||||
- No client-side feature should require the server's out-of-scope items (§8 of the server doc) to exist — the UI shouldn't imply functionality the backend doesn't have.
|
||||
- MVP surface: inbox list, thread view, compose/reply, tag/folder management, rule management, search. Resist adding more until this is solid.
|
||||
- Server-side rendering is probably unnecessary — this is an authenticated, logged-in-only app, not something that needs to be crawlable or SEO-friendly.
|
||||
|
||||
---
|
||||
|
||||
## 2. No PWA — Plain Webapp (for now)
|
||||
|
||||
**Decided: drop PWA entirely for the initial build.** No web app manifest, no service worker, no installability, no offline app-shell caching. Just a regular webapp, opened in a browser tab, kept simple. This is a scope cut in line with §1's "fast and simple over feature-complete" priority — PWA infrastructure (manifest, service worker lifecycle, cache versioning, offline fallback states) is real complexity that isn't needed for a first version. See §8 for bringing it back later.
|
||||
|
||||
Practical effect: no offline app-shell, no "Install" affordance in either browser, no Web Push notifications (§3 below covers what replaces this for now).
|
||||
|
||||
---
|
||||
|
||||
## 3. Notifications (WebSocket + polling, no push)
|
||||
|
||||
Without a service worker (§2), Web Push isn't available, so notifications work only while the tab is open — which matches dropping PWA for now:
|
||||
|
||||
- **WebSocket**: the primary path, as already scoped server-side — the server pushes events (new mail, flag change, rule action) to any open tab in real time.
|
||||
- **Polling fallback**: a simple `GET /events?since=<cursor>` for degraded connections or if a WebSocket connection drops and hasn't reconnected yet.
|
||||
- In-tab notifications only (a toast/badge inside the UI, or the `Notification` API for an OS-level notification while the tab is open — `Notification.requestPermission()` + `new Notification(...)` works without a service worker, it just can't fire when the tab/browser is fully closed).
|
||||
- The always-on, closed-tab notification experience ("just works" even when not looking at it) stays the Android app's job for now, via UnifiedPush — see the Android design doc. Bringing that same experience to the webapp is what PWA + Web Push (§8) would add back later.
|
||||
|
||||
---
|
||||
|
||||
## 4. Theming
|
||||
|
||||
No dynamic/system-extracted color for the webapp — decided against it. **Palette is decided** (same values as the branding doc — kept here too since it's what the CSS actually consumes):
|
||||
|
||||
```css
|
||||
:root[data-theme="light"] {
|
||||
--text: #0c0a10;
|
||||
--background: #f4f3f7;
|
||||
--primary: #988fa8;
|
||||
--secondary: #c3c7d5;
|
||||
--accent: #f39a39;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--text: #f1eff5;
|
||||
--background: #09080c;
|
||||
--primary: #605770;
|
||||
--secondary: #2a2e3c;
|
||||
--accent: #c66c0c;
|
||||
}
|
||||
```
|
||||
|
||||
- Let the user choose Light / Dark / Follow system in-app (stored preference — `localStorage` is fine given this is a desktop-only, per-browser app; no need to sync it to the account).
|
||||
- Use the `light-dark()` CSS function (Chrome/Edge 123+, Firefox 120+ — safely inside your desktop Chrome+Firefox target) to define both values in one place instead of duplicating rules inside `@media (prefers-color-scheme: dark)` blocks. Requires `color-scheme: light dark;` set on `:root` for it to activate. The `data-theme` attribute approach above (rather than relying on `light-dark()` alone) is what lets "Follow system" vs. an explicit user override both work cleanly — set `data-theme` from the resolved preference, and reference `light-dark()` and/or these custom properties inside the CSS either way.
|
||||
- Set `<meta name="theme-color">` with a `media` attribute for light/dark variants, so the browser UI (address bar/tab color) matches your current theme immediately, before your CSS loads.
|
||||
|
||||
---
|
||||
|
||||
## 4a. Desktop-Specific Design Considerations
|
||||
|
||||
Since this isn't a touch/mobile design, several defaults flip compared to a typical PWA:
|
||||
|
||||
- **Two-pane layout by default**, not single-pane-first: a list + reading pane (Gmail/Outlook-style) is the natural desktop layout and doesn't need to be "unlocked" at a breakpoint the way a mobile-first design would — design for it as the base case.
|
||||
- **Hover states, not swipe gestures**: reveal row actions (archive/tag/delete) on row hover rather than building touch-swipe interactions you don't need. Simpler to build and more discoverable on desktop anyway — fits the "simple" priority.
|
||||
- **Keyboard shortcuts matter a lot here** — arguably more than on mobile. Desktop mail power-users expect Gmail-style single-key navigation (e.g. `j`/`k` to move between messages, `e` to archive, `/` to focus search, `c` to compose). This is a cheap, high-value way to make the app feel "fast," which is your stated top priority — worth treating as core UX, not a stretch feature.
|
||||
- **Right-click context menus** are a natural fit for list-row actions (move to folder, apply tag, mark as spam) instead of needing an explicit "..." menu button on every row.
|
||||
- **No safe-area-inset / gesture-nav handling needed** — that's an Android-specific concern from the client design doc and doesn't apply here.
|
||||
- Mobile-oriented APIs (Web Share, touch-optimized tap targets) can be skipped entirely rather than "supported but untested" — this app isn't targeting a phone browser.
|
||||
|
||||
---
|
||||
|
||||
## 5. Modern Web Platform APIs (desktop Firefox + Chromium)
|
||||
|
||||
**Decided: only build on APIs supported in both current desktop Chrome and Firefox.** No Chromium-only features, even as an optional/feature-detected extra — keeps the codebase and testing surface simple, and avoids a two-tier experience between browsers.
|
||||
|
||||
- `light-dark()` CSS function (§4)
|
||||
- CSS nesting (native, no preprocessor needed)
|
||||
- CSS `:has()` selector — useful for parent-aware styling (e.g. style a list row differently when it contains an unread indicator) without extra JS
|
||||
- Container queries (`@container`) — useful for component-level layout (e.g. a reading pane that reflows if the user resizes it), less critical than on a responsive mobile design but still handy
|
||||
- `<dialog>` element — native modals (compose window, confirmation dialogs) without a JS modal library
|
||||
- `popover` attribute / Popover API — native lightweight popovers/menus (Chrome 114+, Firefox 125+), good fit for a "simple over heavy" philosophy since it replaces a chunk of what a UI library would otherwise provide — especially useful for right-click context menus (§4a)
|
||||
- `:focus-visible` and `:focus-within` — keyboard-vs-pointer-aware focus styling, matters more here given the keyboard-shortcut-heavy interaction model (§4a)
|
||||
- IndexedDB — for the local cache
|
||||
|
||||
For things a Chromium-only API would otherwise cover (e.g. native save-file dialogs, a taskbar unread-count badge, background retry sync), use the plain cross-browser equivalent instead: a standard `<a download>` link, a favicon/title unread-count update, and an IndexedDB-backed retry queue driven by the `online` event, respectively.
|
||||
|
||||
---
|
||||
|
||||
## 6. Rendering Untrusted HTML Mail
|
||||
|
||||
Same constraint as noted in the server doc, restated here as a client concern:
|
||||
- Sandbox rendered HTML email (`<iframe sandbox>` with a strict CSP, or a strict sanitizer allow-list) — this is a real XSS surface, not optional polish.
|
||||
- Block remote image loading by default (tracking-pixel/read-receipt vector) with a per-message or per-sender "load images" action.
|
||||
|
||||
---
|
||||
|
||||
## 8. Future Plans (explicitly deferred, not designed yet)
|
||||
|
||||
- **PWA (manifest + service worker + installability + Web Push)** — bring back what §2 drops, once the plain webapp is solid. This is what would let the webapp match the Android app's "leave it closed and it still notifies you" behavior. Design note for whenever this happens: keep it additive (the plain webapp keeps working with no manifest present) rather than a rewrite.
|
||||
- **Desktop app** — a native-feeling desktop wrapper (e.g. Tauri, which is lighter-weight than Electron and fits the "fast and simple" philosophy better) once the webapp UI is stable, for people who want a proper installed app with an OS taskbar/dock presence, unread badge, and native notifications without relying on Chrome's PWA install support (relevant given Firefox desktop has none — see the earlier discussion this doc was built on). Wrapping the same webapp UI means this stays low-cost rather than a second UI to maintain.
|
||||
|
||||
---
|
||||
|
||||
## 9. Open Items for Later
|
||||
|
||||
- Exact keyboard shortcut scheme (§4a) — worth nailing down once the core list/thread UI exists, so shortcuts map to real actions rather than being designed in the abstract.
|
||||
- Whether an unread-count favicon/title update (§5) is worth adding now or waits for the future desktop app/PWA work, since it's cheap either way.
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<!-- Match browser chrome to the theme before CSS loads (webapp-client-spec.md §4). -->
|
||||
<meta name="theme-color" content="#f4f3f7" media="(prefers-color-scheme: light)" />
|
||||
<meta name="theme-color" content="#09080c" media="(prefers-color-scheme: dark)" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<title>Tern</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1480
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "tern-web",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"svelte": "^5.1.0",
|
||||
"svelte-check": "^4.0.5",
|
||||
"typescript": "^5.6.3",
|
||||
"vite": "^5.4.10"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<!-- Placeholder mark: a simple wing/chevron per branding-spec.md §2's
|
||||
fallback direction. Not the final icon — real icon design is an
|
||||
open item in that doc. -->
|
||||
<path d="M2 22 L16 8 L30 22 L23 22 L16 15 L9 22 Z" fill="#f39a39" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 320 B |
@@ -0,0 +1,77 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { applyTheme, loadThemePreference, saveThemePreference, type ThemePreference } from './lib/theme';
|
||||
import { getSessionToken } from './lib/api';
|
||||
import AuthGate from './lib/AuthGate.svelte';
|
||||
import MailShell from './lib/MailShell.svelte';
|
||||
|
||||
let authenticated = $state(getSessionToken() !== null);
|
||||
let theme = $state<ThemePreference>('system');
|
||||
|
||||
onMount(() => {
|
||||
theme = loadThemePreference();
|
||||
applyTheme(theme);
|
||||
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
const onChange = () => {
|
||||
if (theme === 'system') applyTheme(theme);
|
||||
};
|
||||
media.addEventListener('change', onChange);
|
||||
return () => media.removeEventListener('change', onChange);
|
||||
});
|
||||
|
||||
function setTheme(pref: ThemePreference) {
|
||||
theme = pref;
|
||||
saveThemePreference(pref);
|
||||
applyTheme(pref);
|
||||
}
|
||||
</script>
|
||||
|
||||
<header class="topbar">
|
||||
<span class="brand">Tern</span>
|
||||
<div class="theme-switch">
|
||||
{#each ['light', 'dark', 'system'] as const as option}
|
||||
<button class:active={theme === option} onclick={() => setTheme(option)}>{option}</button>
|
||||
{/each}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
{#if authenticated}
|
||||
<MailShell />
|
||||
{:else}
|
||||
<AuthGate onAuthenticated={() => (authenticated = true)} />
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.topbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
border-bottom: 1px solid var(--secondary);
|
||||
}
|
||||
.brand {
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
}
|
||||
.theme-switch {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.theme-switch button {
|
||||
background: none;
|
||||
border: 1px solid var(--secondary);
|
||||
color: var(--text);
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.25rem 0.6rem;
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.theme-switch button.active {
|
||||
background: var(--secondary);
|
||||
}
|
||||
main {
|
||||
height: calc(100% - 3rem);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script lang="ts">
|
||||
import { login } from './api';
|
||||
|
||||
let { onAuthenticated }: { onAuthenticated: () => void } = $props();
|
||||
|
||||
let username = $state('');
|
||||
let password = $state('');
|
||||
let error = $state<string | null>(null);
|
||||
let submitting = $state(false);
|
||||
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
error = null;
|
||||
submitting = true;
|
||||
try {
|
||||
await login(username, password);
|
||||
onAuthenticated();
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : 'login failed';
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<form class="auth-gate" onsubmit={handleSubmit}>
|
||||
<h1>Tern</h1>
|
||||
<label>
|
||||
Username
|
||||
<input type="text" bind:value={username} autocomplete="username" required />
|
||||
</label>
|
||||
<label>
|
||||
Password
|
||||
<input type="password" bind:value={password} autocomplete="current-password" required />
|
||||
</label>
|
||||
{#if error}
|
||||
<p class="error">{error}</p>
|
||||
{/if}
|
||||
<button type="submit" disabled={submitting}>{submitting ? 'Signing in…' : 'Sign in'}</button>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.auth-gate {
|
||||
max-width: 20rem;
|
||||
margin: 15vh auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
input {
|
||||
padding: 0.5rem;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.375rem;
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
}
|
||||
button {
|
||||
padding: 0.6rem;
|
||||
border: none;
|
||||
border-radius: 0.375rem;
|
||||
background: var(--accent);
|
||||
color: var(--text);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error {
|
||||
color: var(--accent);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,126 @@
|
||||
<script lang="ts">
|
||||
// Two-pane layout is the base case here, not a breakpoint-unlocked
|
||||
// extra (webapp-client-spec.md §4a) — this is a desktop-first app.
|
||||
import { onMount } from 'svelte';
|
||||
import { listFolders, listMessages, type Folder, type MessageSummary } from './api';
|
||||
|
||||
let folders = $state<Folder[]>([]);
|
||||
let messages = $state<MessageSummary[]>([]);
|
||||
let selectedFolderId = $state<string | undefined>(undefined);
|
||||
let selectedMessage = $state<MessageSummary | null>(null);
|
||||
let loadError = $state<string | null>(null);
|
||||
|
||||
async function refresh() {
|
||||
loadError = null;
|
||||
try {
|
||||
folders = await listFolders();
|
||||
const page = await listMessages({ folderId: selectedFolderId });
|
||||
messages = page.messages;
|
||||
} catch (err) {
|
||||
loadError = err instanceof Error ? err.message : 'failed to load';
|
||||
}
|
||||
}
|
||||
|
||||
onMount(refresh);
|
||||
|
||||
function selectFolder(id: string | undefined) {
|
||||
selectedFolderId = id;
|
||||
selectedMessage = null;
|
||||
refresh();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="shell">
|
||||
<nav class="folders">
|
||||
<button class:active={!selectedFolderId} onclick={() => selectFolder(undefined)}>All Mail</button>
|
||||
{#each folders as folder (folder.id)}
|
||||
<button class:active={selectedFolderId === folder.id} onclick={() => selectFolder(folder.id)}>
|
||||
{folder.name}
|
||||
</button>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
<section class="list">
|
||||
{#if loadError}
|
||||
<p class="error">{loadError}</p>
|
||||
{:else if messages.length === 0}
|
||||
<p class="empty">No messages yet — this is a scaffold, the sync engine + tag/rule UI land in a later phase.</p>
|
||||
{:else}
|
||||
{#each messages as message (message.id)}
|
||||
<button class="row" class:selected={selectedMessage?.id === message.id} onclick={() => (selectedMessage = message)}>
|
||||
<strong>{message.from_name || message.from_addr || 'Unknown sender'}</strong>
|
||||
<span>{message.subject || '(no subject)'}</span>
|
||||
</button>
|
||||
{/each}
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="reading-pane">
|
||||
{#if selectedMessage}
|
||||
<h2>{selectedMessage.subject || '(no subject)'}</h2>
|
||||
<p class="meta">From {selectedMessage.from_name || selectedMessage.from_addr}</p>
|
||||
<p class="placeholder">
|
||||
Body rendering (sandboxed iframe + remote-image blocking per §6) isn't wired up yet in this scaffold.
|
||||
</p>
|
||||
{:else}
|
||||
<p class="placeholder">Select a message to read it.</p>
|
||||
{/if}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.shell {
|
||||
display: grid;
|
||||
grid-template-columns: 14rem 20rem 1fr;
|
||||
height: 100%;
|
||||
}
|
||||
.folders {
|
||||
background: var(--primary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.75rem;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.folders button {
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text);
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.folders button.active {
|
||||
background: var(--secondary);
|
||||
}
|
||||
.list {
|
||||
border-right: 1px solid var(--secondary);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
padding: 0.75rem 1rem;
|
||||
border: none;
|
||||
border-bottom: 1px solid var(--secondary);
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
}
|
||||
.row:hover,
|
||||
.row.selected {
|
||||
background: var(--secondary);
|
||||
}
|
||||
.reading-pane {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
.empty,
|
||||
.placeholder,
|
||||
.error {
|
||||
padding: 1rem;
|
||||
color: var(--primary);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,72 @@
|
||||
// Thin client for tern-server's REST API (server-architecture-spec.md §4).
|
||||
// Deliberately minimal for this scaffold phase — just enough to prove the
|
||||
// two-pane shell can talk to the server once accounts/messages exist.
|
||||
|
||||
const SESSION_KEY = 'tern-session-token';
|
||||
|
||||
export function getSessionToken(): string | null {
|
||||
return localStorage.getItem(SESSION_KEY);
|
||||
}
|
||||
|
||||
export function setSessionToken(token: string): void {
|
||||
localStorage.setItem(SESSION_KEY, token);
|
||||
}
|
||||
|
||||
export function clearSessionToken(): void {
|
||||
localStorage.removeItem(SESSION_KEY);
|
||||
}
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const token = getSessionToken();
|
||||
const res = await fetch(`/api${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
...init?.headers,
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error ?? `request failed: ${res.status}`);
|
||||
}
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export interface Folder {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface MessageSummary {
|
||||
id: string;
|
||||
subject: string | null;
|
||||
from_addr: string | null;
|
||||
from_name: string | null;
|
||||
sent_at: string | null;
|
||||
thread_id: string;
|
||||
flags: string[];
|
||||
}
|
||||
|
||||
export function listFolders(): Promise<Folder[]> {
|
||||
return request('/folders');
|
||||
}
|
||||
|
||||
export function listMessages(params: { folderId?: string; before?: string } = {}): Promise<{
|
||||
messages: MessageSummary[];
|
||||
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(`/messages${qs ? `?${qs}` : ''}`);
|
||||
}
|
||||
|
||||
export async function login(username: string, password: string): Promise<void> {
|
||||
const res = await request<{ token: string }>('/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
setSessionToken(res.token);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export type ThemePreference = 'light' | 'dark' | 'system';
|
||||
|
||||
const STORAGE_KEY = 'tern-theme';
|
||||
|
||||
export function loadThemePreference(): ThemePreference {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored === 'light' || stored === 'dark' || stored === 'system' ? stored : 'system';
|
||||
}
|
||||
|
||||
export function saveThemePreference(pref: ThemePreference): void {
|
||||
localStorage.setItem(STORAGE_KEY, pref);
|
||||
}
|
||||
|
||||
export function applyTheme(pref: ThemePreference): void {
|
||||
const resolved =
|
||||
pref === 'system'
|
||||
? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
|
||||
: pref;
|
||||
document.documentElement.dataset.theme = resolved;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import './theme.css';
|
||||
import { mount } from 'svelte';
|
||||
import App from './App.svelte';
|
||||
|
||||
const app = mount(App, { target: document.getElementById('app')! });
|
||||
|
||||
export default app;
|
||||
@@ -0,0 +1,50 @@
|
||||
/* Palette from branding-spec.md / webapp-client-spec.md §4 — final, consumed
|
||||
directly as custom properties, no generation step. `data-theme` (set from
|
||||
resolved preference: explicit choice, or system via matchMedia) drives
|
||||
which block applies; `color-scheme` + light-dark() would also work but the
|
||||
data-theme attribute is what lets "Follow system" and an explicit
|
||||
override both work cleanly. */
|
||||
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
:root[data-theme='light'] {
|
||||
--text: #0c0a10;
|
||||
--background: #f4f3f7;
|
||||
--primary: #988fa8;
|
||||
--secondary: #c3c7d5;
|
||||
--accent: #f39a39;
|
||||
}
|
||||
|
||||
:root[data-theme='dark'] {
|
||||
--text: #f1eff5;
|
||||
--background: #09080c;
|
||||
--primary: #605770;
|
||||
--secondary: #2a2e3c;
|
||||
--accent: #c66c0c;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--text);
|
||||
font-family:
|
||||
system-ui,
|
||||
-apple-system,
|
||||
'Segoe UI',
|
||||
sans-serif;
|
||||
}
|
||||
|
||||
#app {
|
||||
height: 100vh;
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,5 @@
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
export default {
|
||||
preprocess: vitePreprocess(),
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.svelte"]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [svelte()],
|
||||
server: {
|
||||
proxy: {
|
||||
// Points at tern-server's default dev bind address (see server/.env.example).
|
||||
'/api': 'http://127.0.0.1:8080',
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user