feat: restyle the ui in gmail's design language

This commit is contained in:
randogoth 2026-09-26 16:52:40 +03:00
parent a6b972fec9
commit 9842302c50
3 changed files with 288 additions and 132 deletions

View file

@ -7,14 +7,15 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>smol mail</h1>
<div id="account" class="account"></div>
<nav class="actions">
<header class="topbar">
<div class="brand">smol mail</div>
<input id="search" class="search" placeholder="search mail" spellcheck="false">
<div class="top-actions">
<button id="fetch">fetch</button>
<button id="write">write</button>
<button id="settings-open">settings</button>
</nav>
<div id="account" class="account"></div>
<div id="avatar" class="avatar"></div>
</div>
</header>
<main id="setup" class="setup" hidden>
@ -29,10 +30,13 @@
</main>
<main id="app" hidden>
<nav id="folders" class="folders">
<button data-folder="inbox" class="active">inbox</button>
<button data-folder="sent">sent</button>
<button data-folder="contacts">contacts</button>
<nav class="rail">
<button id="write" class="compose">compose</button>
<div id="folders">
<button data-folder="inbox" class="active">inbox <span id="count-inbox" class="count"></span></button>
<button data-folder="sent">sent</button>
<button data-folder="contacts">contacts</button>
</div>
</nav>
<section id="list" class="list"></section>
<article id="view" class="view"><p class="placeholder">select a message</p></article>
@ -40,9 +44,9 @@
<dialog id="compose">
<form id="compose-form" method="dialog">
<label>to <input name="to" required spellcheck="false" placeholder="alice@example.org or smol://…"></label>
<label>subject <input name="subject" spellcheck="false"></label>
<textarea name="body" rows="12"></textarea>
<input name="to" required spellcheck="false" placeholder="to: alice@example.org or smol://…">
<input name="subject" spellcheck="false" placeholder="subject">
<textarea name="body" rows="12" placeholder="message"></textarea>
<footer>
<label class="anon"><input type="checkbox" name="anonymous"> anonymous — omit my address</label>
<span id="compose-error" class="error"></span>
@ -87,7 +91,7 @@
<footer><button id="settings-close">close</button></footer>
</dialog>
<div id="status" class="status"></div>
<div id="status" class="toast" hidden></div>
<script type="module" src="js/app.js"></script>
</body>
</html>

View file

@ -12,14 +12,28 @@ import { connectStream } from "./transport.js";
const $ = (id) => document.getElementById(id);
// The status line is a toast: click to dismiss, empty means hidden.
function status(text, warn = false) {
$("status").textContent = text;
$("status").className = warn ? "status warn" : "status";
const toast = $("status");
toast.textContent = text;
toast.hidden = !text;
toast.className = "toast" + (warn ? " warn" : "");
}
$("status").onclick = () => status("");
const fmtTime = (seconds) =>
new Date(seconds * 1000).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
// Gmail-style row stamp: time for today, date within this year, full date older.
const fmtRowTime = (seconds) => {
const date = new Date(seconds * 1000), today = new Date();
if (date.toDateString() === today.toDateString())
return date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
if (date.getFullYear() === today.getFullYear())
return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
return date.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
};
// The stored account as an address object, default port included when custom.
function accountAddress() {
const account = store.account();
@ -86,8 +100,9 @@ function renderAccount() {
const me = store.identity();
const account = store.account();
$("account").textContent = me
? `${account ? account.user + "@" + account.host : "(not registered)"} · ${fingerprint(me.publicKey)}`
? (account ? `${account.user}@${account.host}` : "not registered")
: "";
$("avatar").textContent = account ? account.user[0].toUpperCase() : "·";
}
// --- folders and list ---------------------------------------------------------
@ -106,30 +121,47 @@ for (const button of $("folders").querySelectorAll("button"))
async function renderFolder() {
const list = $("list");
if (folder === "contacts") return renderContacts(list);
const rows = await store.listMessages(folder);
const rows = [...await store.listMessages(folder)].reverse(); // newest first
list.replaceChildren();
let unread = 0;
for (const row of rows) {
const opened = describe(row);
const isUnread = !store.isRead(row.id);
if (folder === "inbox" && isUnread) unread++;
const item = document.createElement("div");
item.className = "item" + (row.id === selectedId ? " selected" : "");
item.className = `item${row.id === selectedId ? " selected" : ""}${isUnread ? " unread" : ""}`;
const who = document.createElement("div");
who.className = "who" + (store.isRead(row.id) ? "" : " unread");
who.className = "who";
who.textContent = folder === "sent" ? row.recipient : (opened.from ?? "?");
const subject = document.createElement("div");
const mid = document.createElement("div");
mid.className = "mid";
const subject = document.createElement("span");
subject.className = "subject";
subject.textContent = opened.error ? `<unreadable: ${opened.error}>`
: (opened.subject || "(no subject)");
const when = document.createElement("span");
const snippet = document.createElement("span");
snippet.className = "snippet";
snippet.textContent = opened.error ? "" : ` — ${opened.snippet}`;
mid.append(subject, snippet);
const when = document.createElement("div");
when.className = "when";
when.textContent = fmtTime(folder === "sent" ? row.sentAt : opened.time ?? row.receivedAt);
item.append(who, subject, when);
when.textContent = fmtRowTime(folder === "sent" ? row.sentAt : (opened.time ?? row.receivedAt));
item.append(who, mid, when);
item.onclick = () => openMessage(row.id);
list.append(item);
}
$("count-inbox").textContent = folder === "inbox" && unread ? String(unread) : "";
if (!rows.length) list.append(Object.assign(document.createElement("p"),
{ className: "placeholder", textContent: folder === "inbox" ? "no mail — fetch" : "nothing sent" }));
}
// The header search filters the rendered list client-side; nothing leaves the page.
$("search").oninput = () => {
const query = $("search").value.trim().toLowerCase();
for (const item of $("list").querySelectorAll(".item"))
item.hidden = Boolean(query) && !item.textContent.toLowerCase().includes(query);
};
// Open an envelope and split its body; anything unreadable shows as such
// rather than throwing, so one bad message cannot blank the list. The wire
// carries no sender name, so an unknown key can only be shown as its
@ -154,6 +186,7 @@ function describe(row) {
...opened,
fields, body,
subject: fields.Subject || "",
snippet: body.replace(/\s+/g, " ").trim().slice(0, 140),
from: known ?? `unknown · ${fingerprint(opened.sender)}`,
knownSender: Boolean(known),
replyAddress,
@ -174,21 +207,26 @@ async function openMessage(id) {
const opened = describe(row);
const view = $("view");
if (opened.error) {
view.innerHTML = `<p class="placeholder warn">${opened.error}</p>`;
view.replaceChildren();
const note = document.createElement("p");
note.className = "placeholder warn";
note.textContent = opened.error;
view.append(note);
return;
}
const fields = Object.entries(opened.fields).filter(([k]) => k !== "Subject");
view.innerHTML = `<h2></h2><div class="meta"></div><div class="fields"></div>` +
`<div class="verified">signature verified</div><pre></pre>`;
`<div class="verified">signature verified</div><pre></pre><div class="actions"></div>`;
view.querySelector("h2").textContent = opened.subject || "(no subject)";
view.querySelector(".meta").textContent = folder === "sent"
? `to: ${row.recipient}\nid: ${row.id}\nsent: ${fmtTime(row.sentAt)}`
: `from: ${opened.from}\nkey: ${b32encode(opened.sender)}\nid: ${row.id}\ndate: ${fmtTime(opened.time)}`;
view.querySelector(".fields").textContent = fields.map(([k, v]) => `${k}: ${v}`).join("\n");
view.querySelector("pre").textContent = opened.body;
const actions = view.querySelector(".actions");
if (folder === "inbox") {
if (opened.knownSender) {
view.append(replyButton(opened, row));
actions.append(replyButton(opened, row));
} else if (opened.replyAddress) {
// The sender signed their own smol:// address into the payload, so
// binding it is one click. A pinned conflicting key is refused (§8).
@ -196,6 +234,7 @@ async function openMessage(id) {
note.className = "placeholder";
note.textContent =
`this message carries the sender's signed address: ${opened.replyAddress.short}`;
actions.before(note);
const save = document.createElement("button");
save.textContent = "save sender & reply";
save.onclick = () => {
@ -211,7 +250,7 @@ async function openMessage(id) {
status(err.message, true);
}
};
view.append(note, save);
actions.append(save);
} else {
// The wire gives only a signed key; a reply needs the sender's address,
// which the user supplies once and we bind to that exact key.
@ -244,7 +283,7 @@ async function openMessage(id) {
name.disabled = false;
}
};
view.append(note, form);
actions.append(note, form);
}
}
}
@ -436,13 +475,13 @@ function renderContacts(list) {
const who = document.createElement("div");
who.className = "who";
who.textContent = address;
const fp = document.createElement("div");
fp.className = "subject";
fp.textContent = `${fingerprint(b32decode(key))} · ${verified ? "verified key" : "tofu"}`;
const mid = document.createElement("div");
mid.className = "mid";
mid.textContent = `${fingerprint(b32decode(key))} · ${verified ? "verified key" : "tofu"}`;
const refresh = document.createElement("button");
refresh.textContent = "refresh";
refresh.onclick = () => refreshContact(address);
item.append(who, fp, refresh);
item.append(who, mid, refresh);
list.append(item);
}
if (!contacts.length) list.append(Object.assign(document.createElement("p"),
@ -497,14 +536,28 @@ function renderSettings() {
const me = store.identity();
const account = store.account();
const card = $("identity-card");
if (!me) { card.textContent = ""; return; }
const share = account ? accountAddress().uri(me.publicKey) : "(register to get a shareable address)";
card.innerHTML = `<div>fingerprint: ${fingerprint(me.publicKey)}</div>` +
`<div>address: ${account ? account.user + "@" + account.host : "(not registered)"}</div>` +
`<div>share: ${share}</div>` +
`<div class="seed">${hex(me.seed)}</div>` +
`<div class="warn">back this seed up; it is the only secret</div>` +
`<div>retired keys: ${store.identities().length - 1} (kept to read old mail)</div>`;
card.replaceChildren();
if (!me) return;
const lines = [
`fingerprint: ${fingerprint(me.publicKey)}`,
`address: ${account ? account.user + "@" + account.host : "(not registered)"}`,
`share: ${account ? accountAddress().uri(me.publicKey) : "(register to get a shareable address)"}`,
"",
];
for (const text of lines) {
const div = document.createElement("div");
div.textContent = text;
card.append(div);
}
const seed = document.createElement("div");
seed.className = "seed";
seed.textContent = hex(me.seed);
const warning = document.createElement("div");
warning.className = "warn";
warning.textContent = "back this seed up; it is the only secret";
const retired = document.createElement("div");
retired.textContent = `retired keys: ${store.identities().length - 1} (kept to read old mail)`;
card.append(seed, warning, retired);
const pins = $("pins");
pins.replaceChildren();

View file

@ -1,151 +1,250 @@
:root {
--bg: #fafaf7;
--fg: #26251f;
--muted: #7a766b;
--line: #dcd8cc;
--accent: #3a5a40;
--warn: #9c3f2c;
--bg: #f6f8fc;
--surface: #ffffff;
--fg: #202124;
--muted: #5f6368;
--border: #dadce0;
--accent: #1a73e8;
--accent-soft: #e8f0fe;
--hover: #f1f3f4;
--warn: #d93025;
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
--radius: 8px;
--shadow: 0 1px 3px rgba(60, 64, 67, 0.2), 0 4px 8px 3px rgba(60, 64, 67, 0.08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
font: 15px/1.5 system-ui, sans-serif;
font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
color: var(--fg);
background: var(--bg);
background: var(--surface);
}
button {
font: inherit;
padding: 4px 14px;
border: 1px solid var(--line);
border-radius: 4px;
background: #fff;
border: 0;
border-radius: var(--radius);
background: none;
color: var(--accent);
padding: 6px 14px;
cursor: pointer;
white-space: nowrap;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
header {
display: flex;
align-items: center;
gap: 16px;
padding: 8px 16px;
border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
.actions { margin-left: auto; display: flex; gap: 8px; }
.account { font-family: var(--mono); font-size: 13px; color: var(--muted); }
main { flex: 1; min-height: 0; display: flex; }
.setup { flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.setup h2 { margin: 0; }
.setup .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
button:hover { background: var(--hover); }
button:disabled { color: var(--muted); cursor: default; }
input, textarea {
font: inherit;
font-family: var(--mono);
font-size: 13px;
padding: 4px 8px;
border: 1px solid var(--line);
border-radius: 4px;
background: #fff;
padding: 6px 10px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--surface);
color: var(--fg);
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
/* --- top bar --------------------------------------------------------------- */
.topbar {
display: flex;
align-items: center;
gap: 16px;
padding: 10px 16px;
border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 500; letter-spacing: -0.02em; }
.search {
flex: 1;
max-width: 640px;
margin: 0 auto;
background: var(--hover);
border: 0;
border-radius: var(--radius);
padding: 8px 16px;
}
.search:focus { background: var(--surface); outline: 1px solid var(--border); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.account { font-size: 13px; color: var(--muted); margin-right: 4px; }
.avatar {
width: 32px;
height: 32px;
border-radius: 50%;
background: var(--accent);
color: #fff;
font-size: 15px;
font-weight: 500;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
}
.folders {
/* --- layout ------------------------------------------------------------------ */
main { flex: 1; min-height: 0; display: flex; background: var(--bg); }
.rail {
width: 200px;
padding: 12px 8px;
background: var(--surface);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
border-right: 1px solid var(--line);
min-width: 110px;
gap: 4px;
}
.folders button {
border: 0;
border-bottom: 1px solid var(--line);
border-radius: 0;
.compose {
align-self: flex-start;
margin: 0 8px 16px;
padding: 12px 26px;
border-radius: 20px;
background: var(--accent-soft);
color: var(--accent);
font-weight: 500;
box-shadow: var(--shadow);
}
.compose:hover { background: var(--accent); color: #fff; }
#folders button {
display: flex;
align-items: center;
justify-content: space-between;
text-align: left;
padding: 10px 14px;
background: none;
padding: 8px 16px;
color: var(--fg);
font-weight: 500;
}
#folders button:hover { background: var(--hover); }
#folders button.active { background: var(--accent-soft); color: var(--accent); }
#folders .count { color: var(--accent); font-weight: 500; margin-left: 8px; }
.list {
min-width: 280px;
max-width: 380px;
min-width: 360px;
max-width: 460px;
overflow-y: auto;
border-right: 1px solid var(--line);
background: var(--surface);
border-right: 1px solid var(--border);
}
.item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: #f1efe6; }
.item.selected { background: #ece9dd; }
.item .who { font-weight: 600; }
.item .who.unread::before { content: "● "; color: var(--accent); }
.item .subject { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { float: right; font-size: 12px; color: var(--muted); }
.view { flex: 1; overflow-y: auto; padding: 20px 24px; }
.placeholder { color: var(--muted); font-style: italic; }
.view h2 { margin: 0 0 2px; font-size: 17px; }
.view .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.view .fields { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.item {
display: flex;
gap: 12px;
align-items: baseline;
padding: 9px 16px;
border-bottom: 1px solid #eee;
cursor: pointer;
color: var(--muted);
}
.item:hover { background: var(--hover); }
.item.selected { background: var(--accent-soft); }
.item.unread { color: var(--fg); }
.item .who { width: 150px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .mid { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .subject { font-weight: 400; }
.item.unread .who { font-weight: 700; }
.item.unread .subject { font-weight: 700; }
.item .snippet { color: var(--muted); }
.item.unread .snippet { color: var(--fg); }
.item .when { flex: none; font-size: 12px; color: var(--muted); }
.item button { padding: 2px 12px; font-size: 12px; }
.view { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 28px; }
.view h2 { margin: 0 0 10px; font-size: 20px; font-weight: 400; }
.view .meta { font-size: 13px; color: var(--muted); margin-bottom: 14px; white-space: pre-line; }
.view .fields { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 10px; white-space: pre-line; }
.view pre {
white-space: pre-wrap;
font-family: inherit;
margin: 12px 0 0;
border-top: 1px solid var(--line);
padding-top: 12px;
margin: 14px 0 0;
padding: 14px 0 0;
border-top: 1px solid var(--border);
}
.view .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.view .actions button { border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--fg); }
.view .actions button:hover { background: var(--hover); color: var(--fg); }
.verified {
display: inline-block;
font-size: 12px;
padding: 2px 10px;
border-radius: 12px;
background: #e6f4ea;
color: #137333;
}
.verified { color: var(--accent); font-size: 12px; }
.warn { color: var(--warn); }
.placeholder { color: var(--muted); font-style: italic; padding: 12px 16px; }
.name-sender { display: flex; gap: 8px; margin: 12px 0 0; }
.name-sender input { flex: 1; }
/* --- setup -------------------------------------------------------------------- */
.setup {
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
text-align: center;
background: var(--bg);
}
.setup h2 { margin: 0; font-weight: 400; }
.setup p { color: var(--muted); max-width: 480px; }
.setup .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
/* --- dialogs --------------------------------------------------------------------- */
dialog {
border: 1px solid var(--line);
border-radius: 8px;
padding: 20px;
border: 0;
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 20px 24px;
min-width: 460px;
max-width: 640px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.25); }
#compose form { display: flex; flex-direction: column; gap: 8px; }
#compose label { display: flex; gap: 8px; align-items: center; }
#compose input { flex: 1; }
#compose textarea { font-family: inherit; }
#compose footer { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
#compose .anon { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.error { color: var(--warn); font-size: 13px; margin-right: auto; }
dialog::backdrop { background: rgba(32, 33, 36, 0.3); }
#compose form { display: flex; flex-direction: column; gap: 10px; }
#compose input, #compose textarea { width: 100%; }
#compose textarea { font-family: inherit; resize: vertical; }
#compose footer { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 4px; }
#compose .anon { font-size: 13px; color: var(--muted); margin-right: auto; display: flex; align-items: center; gap: 6px; }
.error { color: var(--warn); font-size: 13px; }
#settings section { margin-bottom: 20px; }
#settings form { display: flex; gap: 8px; margin: 8px 0; }
#settings form input { flex: 1; }
#settings h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#settings section { margin-bottom: 22px; }
#settings h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#settings form { display: flex; gap: 8px; margin: 6px 0; }
#settings form input { flex: 1; font-family: var(--mono); font-size: 13px; }
#settings footer { display: flex; justify-content: flex-end; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0; }
.kv { list-style: none; padding: 0; margin: 4px 0; font-family: var(--mono); font-size: 12px; }
.kv { list-style: none; padding: 0; margin: 6px 0; font-size: 13px; }
.kv li { display: flex; gap: 10px; padding: 3px 0; align-items: baseline; }
.kv li button { padding: 0 8px; font-size: 11px; }
.kv .key { word-break: break-all; color: var(--muted); flex: 1; }
.kv .key { font-family: var(--mono); word-break: break-all; color: var(--muted); flex: 1; }
#identity-card { font-family: var(--mono); font-size: 12px; }
#identity-card div { margin: 4px 0; word-break: break-all; }
#identity-card .seed { border: 1px dashed var(--warn); padding: 6px; }
.status {
/* --- toast ------------------------------------------------------------------------ */
.toast {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 6px 16px;
left: 24px;
bottom: 24px;
max-width: 520px;
margin: 0;
padding: 12px 18px;
border-radius: var(--radius);
background: #202124;
color: #e8eaed;
font-size: 13px;
border-top: 1px solid var(--line);
background: #fff;
min-height: 30px;
white-space: pre-wrap;
box-shadow: var(--shadow);
cursor: pointer;
}
.toast.warn { background: var(--warn); color: #fff; }
.toast[hidden] { display: none; }