checkpoint

This commit is contained in:
2026-10-28 13:23:35 +02:00
parent cce5e348b3
commit 33dad8ca5a
26 changed files with 1949 additions and 49 deletions
+81
View File
@@ -0,0 +1,81 @@
// Inbox: loads messages as JSON (GET /messages) and marks them read (POST /messages/{id}/read).
const inbox = document.querySelector('.inbox');
const list = inbox.querySelector('.inbox-list');
const status = inbox.querySelector('.inbox-status');
const unreadOnly = inbox.querySelector('.inbox-unread-only');
const t = inbox.dataset;
const dateFormat = new Intl.DateTimeFormat(document.documentElement.lang, { dateStyle: 'medium', timeStyle: 'short' });
async function load() {
try {
const res = await fetch(`${t.api}?unreadOnly=${unreadOnly.checked}`, { headers: { Accept: 'application/json' } });
if (!res.ok || res.redirected) throw new Error(res.status);
render(await res.json());
} catch {
list.replaceChildren();
status.textContent = t.failed;
}
}
// built with textContent only: message bodies are user input
function render(messages) {
status.textContent = messages.length ? '' : t.empty;
list.replaceChildren(...messages.map(m => {
const li = document.createElement('li');
li.className = 'inbox-item' + (m.isRead ? ' is-read' : '');
const meta = document.createElement('div');
meta.className = 'inbox-meta';
const from = document.createElement('strong');
from.textContent = m.anonymous ? t.anonymous : m.senderUsername;
const time = document.createElement('time');
time.dateTime = m.createdAt;
time.textContent = dateFormat.format(new Date(m.createdAt));
meta.append(from, time);
const body = document.createElement('p');
body.className = 'inbox-body';
body.textContent = m.body;
li.append(meta, body);
if (m.anonymous) {
const agent = document.createElement('p');
agent.className = 'inbox-agent';
agent.textContent = m.senderUsername;
li.append(agent);
}
li.append(m.isRead ? readLabel() : markReadButton(m.id, li));
return li;
}));
}
function readLabel() {
const span = document.createElement('span');
span.className = 'inbox-read';
span.textContent = t.read;
return span;
}
function markReadButton(id, li) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'inbox-mark-read';
button.textContent = t.markRead;
button.addEventListener('click', async () => {
button.disabled = true;
const res = await fetch(`${t.api}/${id}/read`, {
method: 'POST',
headers: { RequestVerificationToken: t.token }
});
if (!res.ok) { button.disabled = false; return; }
if (unreadOnly.checked) { li.remove(); if (!list.children.length) status.textContent = t.empty; return; }
li.classList.add('is-read');
button.replaceWith(readLabel());
});
return button;
}
unreadOnly.addEventListener('change', load);
load();
+12
View File
@@ -0,0 +1,12 @@
// forms marked data-once can only be submitted once (no double messages / double registrations)
document.addEventListener('submit', e => {
const form = e.target;
if (!form.matches('form[data-once]')) return;
if (form.dataset.submitted) {
e.preventDefault();
return;
}
form.dataset.submitted = 'true';
// disable after the browser has collected the form data
setTimeout(() => form.querySelectorAll('[type="submit"]').forEach(b => b.disabled = true));
});
+68
View File
@@ -0,0 +1,68 @@
// Gallery slideshow: prev/next, dots, arrow keys, autoplay that pauses on hover/focus.
// The slides are a scroll-snap strip, so swiping on touch screens works natively.
document.querySelectorAll('.slideshow').forEach(show => {
const strip = show.querySelector('.slides');
const slides = [...show.querySelectorAll('.slide')];
const controls = show.querySelector('.slideshow-controls');
if (!strip || slides.length < 2) return;
const dots = [...controls.querySelectorAll('.slide-dots button')];
const toggle = controls.querySelector('.slide-toggle');
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
const intervalMs = 5000;
let current = 0;
let playing = !reducedMotion;
let hovered = false;
let timer = null;
controls.hidden = false;
function goTo(index) {
current = (index + slides.length) % slides.length;
strip.scrollTo({ left: current * strip.clientWidth, behavior: reducedMotion ? 'auto' : 'smooth' });
update();
}
function update() {
dots.forEach((d, i) => d.setAttribute('aria-current', i === current ? 'true' : 'false'));
toggle.textContent = playing ? '❚❚' : '▶';
toggle.setAttribute('aria-label', playing ? toggle.dataset.pause : toggle.dataset.play);
strip.setAttribute('aria-live', playing ? 'off' : 'polite');
}
function schedule() {
clearInterval(timer);
if (playing && !hovered) timer = setInterval(() => goTo(current + 1), intervalMs);
}
controls.querySelector('.slide-prev').addEventListener('click', () => { goTo(current - 1); schedule(); });
controls.querySelector('.slide-next').addEventListener('click', () => { goTo(current + 1); schedule(); });
dots.forEach((d, i) => d.addEventListener('click', () => { goTo(i); schedule(); }));
toggle.addEventListener('click', () => { playing = !playing; update(); schedule(); });
show.addEventListener('keydown', e => {
if (e.key === 'ArrowLeft') { goTo(current - 1); schedule(); }
if (e.key === 'ArrowRight') { goTo(current + 1); schedule(); }
});
// pause while the pointer or keyboard focus is inside
show.addEventListener('pointerenter', () => { hovered = true; schedule(); });
show.addEventListener('pointerleave', () => { hovered = false; schedule(); });
show.addEventListener('focusin', () => { hovered = true; schedule(); });
show.addEventListener('focusout', e => { if (!show.contains(e.relatedTarget)) { hovered = false; schedule(); } });
// keep the dots in sync when the user swipes or scrolls the strip
let scrollEnd;
strip.addEventListener('scroll', () => {
clearTimeout(scrollEnd);
scrollEnd = setTimeout(() => {
current = Math.round(strip.scrollLeft / strip.clientWidth);
update();
}, 100);
});
addEventListener('resize', () => strip.scrollTo({ left: current * strip.clientWidth }));
update();
schedule();
});
+88
View File
@@ -0,0 +1,88 @@
.auth-forms {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1.5rem;
}
.auth-card {
--surface: #fff;
--text: #0f172a;
--muted: #64748b;
--border: #cbd5e1;
--accent: #2563eb;
display: flex;
flex-direction: column;
gap: 0.9rem;
box-sizing: border-box;
width: min(22rem, calc(100vw - 2rem));
padding: 1.75rem;
border-radius: 1rem;
background: var(--surface);
color: var(--text);
box-shadow: 0 20px 50px rgb(0 0 0 / 0.2);
font-family: system-ui, sans-serif;
}
.auth-card h1 {
margin: 0;
font-size: 1.35rem;
}
.auth-card label {
display: flex;
flex-direction: column;
gap: 0.35rem;
font-weight: 600;
font-size: 0.95rem;
}
.auth-card input {
padding: 0.65rem 0.8rem;
border: 1px solid var(--border);
border-radius: 0.6rem;
background: var(--surface);
color: var(--text);
font: inherit;
font-weight: 400;
}
.auth-card input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px rgb(37 99 235 / 0.2);
}
.auth-card .hint {
margin: -0.4rem 0 0;
color: var(--muted);
font-size: 0.85rem;
}
.auth-card button {
padding: 0.7rem 1.2rem;
border: none;
border-radius: 999px;
background: var(--accent);
color: #fff;
font: 600 1rem/1.2 system-ui, sans-serif;
cursor: pointer;
}
.auth-card button:disabled { opacity: 0.6; cursor: wait; }
.auth-card button:focus-visible {
outline: 3px solid rgb(37 99 235 / 0.5);
outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
.auth-card {
--surface: #0f172a;
--text: #e2e8f0;
--muted: #94a3b8;
--border: #334155;
--accent: #3b82f6;
}
}
+136
View File
@@ -0,0 +1,136 @@
.slideshow {
--frame: #0f172a;
--control-bg: #fff;
--control-text: #0f172a;
--dot: rgb(15 23 42 / 0.3);
--dot-active: #2563eb;
box-sizing: border-box;
width: min(60rem, calc(100vw - 2rem));
font-family: system-ui, sans-serif;
}
.slideshow h1 {
margin: 0 0 1rem;
text-align: center;
}
/* scroll-snap strip: works without JS and gives native swipe */
.slides {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
scrollbar-width: none;
border-radius: 1rem;
background: var(--frame);
box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}
.slides::-webkit-scrollbar { display: none; }
.slides:focus-visible {
outline: 3px solid rgb(37 99 235 / 0.5);
outline-offset: 3px;
}
.slide {
flex: 0 0 100%;
margin: 0;
scroll-snap-align: center;
display: grid;
place-items: center;
}
.slide img {
display: block;
width: 100%;
height: min(70vh, 40rem);
object-fit: contain;
}
.slideshow-controls {
display: flex;
align-items: center;
justify-content: center;
gap: 0.75rem;
margin-top: 1rem;
}
.slideshow-controls[hidden] { display: none; }
.slide-prev,
.slide-next,
.slide-toggle {
display: grid;
place-items: center;
width: 2.75rem;
height: 2.75rem;
border: none;
border-radius: 50%;
background: var(--control-bg);
color: var(--control-text);
font: 700 1.4rem/1 system-ui, sans-serif;
cursor: pointer;
box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
transition: transform 0.15s ease;
}
.slide-toggle { font-size: 0.9rem; }
.slide-prev:hover,
.slide-next:hover,
.slide-toggle:hover { transform: scale(1.08); }
.slide-dots {
display: flex;
gap: 0.25rem;
}
/* 1.5rem hit area around a small visible dot */
.slide-dots button {
width: 1.5rem;
height: 1.5rem;
padding: 0;
border: none;
background: transparent;
cursor: pointer;
}
.slide-dots button::before {
content: "";
display: block;
width: 0.65rem;
height: 0.65rem;
margin: auto;
border-radius: 50%;
background: var(--dot);
transition: background-color 0.2s ease, transform 0.2s ease;
}
.slide-dots button[aria-current="true"]::before {
background: var(--dot-active);
transform: scale(1.3);
}
.slideshow-controls button:focus-visible {
outline: 3px solid rgb(37 99 235 / 0.5);
outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
.slideshow {
--control-bg: #1e293b;
--control-text: #e2e8f0;
--dot: rgb(226 232 240 / 0.35);
--dot-active: #60a5fa;
}
}
@media (prefers-reduced-motion: reduce) {
.slide-prev, .slide-next, .slide-toggle,
.slide-dots button::before { transition: none; }
}
@media (max-width: 480px) {
.slide img { height: 55vh; }
}
+123
View File
@@ -0,0 +1,123 @@
.inbox {
--surface: #fff;
--text: #0f172a;
--muted: #64748b;
--border: #e2e8f0;
--accent: #2563eb;
--unread: #2563eb;
box-sizing: border-box;
width: min(44rem, calc(100vw - 2rem));
font-family: system-ui, sans-serif;
color: var(--text);
}
.inbox-header {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 0.5rem 1rem;
}
.inbox-header h1 { margin: 0; }
.inbox-header label {
display: inline-flex;
align-items: center;
gap: 0.4rem;
cursor: pointer;
}
.inbox-header input { accent-color: var(--accent); }
.inbox-status:empty { display: none; }
.inbox-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin: 1rem 0 0;
padding: 0;
list-style: none;
}
.inbox-item {
display: flex;
flex-direction: column;
gap: 0.5rem;
padding: 1rem 1.25rem;
border-left: 4px solid var(--unread);
border-radius: 0.75rem;
background: var(--surface);
box-shadow: 0 2px 10px rgb(0 0 0 / 0.08);
}
.inbox-item.is-read {
border-left-color: var(--border);
opacity: 0.8;
}
.inbox-meta {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 0.25rem 1rem;
}
.inbox-meta strong { overflow-wrap: anywhere; }
.inbox-meta time {
color: var(--muted);
font-size: 0.9rem;
font-variant-numeric: tabular-nums;
}
.inbox-body {
margin: 0;
white-space: pre-wrap;
overflow-wrap: anywhere;
line-height: 1.5;
}
.inbox-agent {
margin: 0;
color: var(--muted);
font-size: 0.8rem;
overflow-wrap: anywhere;
}
.inbox-mark-read {
align-self: flex-end;
padding: 0.5rem 1rem;
border: none;
border-radius: 999px;
background: var(--accent);
color: #fff;
font: 600 0.9rem/1.2 system-ui, sans-serif;
cursor: pointer;
}
.inbox-mark-read:disabled { opacity: 0.6; cursor: wait; }
.inbox-mark-read:focus-visible {
outline: 3px solid rgb(37 99 235 / 0.5);
outline-offset: 2px;
}
.inbox-read {
align-self: flex-end;
color: var(--muted);
font-size: 0.9rem;
}
@media (prefers-color-scheme: dark) {
.inbox {
--surface: #0f172a;
--text: #e2e8f0;
--muted: #94a3b8;
--border: #334155;
--accent: #3b82f6;
--unread: #60a5fa;
}
}
+73 -6
View File
@@ -1,12 +1,12 @@
html, body{
html {
background-color: lightgreen;
}
body {
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
body {
margin: 0;
font-family: system-ui, sans-serif;
}
@@ -16,9 +16,17 @@ main {
display: flex;
flex-direction: column;
justify-content: center;
box-sizing: border-box;
max-width: 100%;
padding: 2rem 1rem;
}
/* photos never wider than the screen (the profile photo has width="600") */
img {
max-width: 100%;
height: auto;
}
/* Navbar */
.site-header {
--nav-bg: rgb(255 255 255 / 0.75);
@@ -43,6 +51,13 @@ main {
box-shadow: 0 1px 0 rgb(15 23 42 / 0.1), 0 4px 16px rgb(15 23 42 / 0.06);
}
.header-end {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.25rem 0.75rem;
}
.main-nav,
.lang-switch {
display: flex;
@@ -75,11 +90,62 @@ main {
color: var(--nav-active-text);
}
.site-header a:focus-visible {
.site-header a:focus-visible,
.logout-form button:focus-visible {
outline: 3px solid rgb(37 99 235 / 0.5);
outline-offset: 2px;
}
.logout-form {
display: flex;
align-items: center;
gap: 0.25rem;
margin: 0;
}
.user-name {
max-width: 14rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--nav-muted);
font-size: 0.9rem;
}
.logout-form button {
padding: 0.45rem 0.9rem;
border: none;
border-radius: 999px;
background: transparent;
color: var(--nav-text);
font: 600 1rem/1.2 system-ui, sans-serif;
cursor: pointer;
transition: background-color 0.15s ease;
}
.logout-form button:hover {
background: var(--nav-hover);
}
/* one-line notice under the header (message sent, login failed, ...) */
.flash {
--flash-bg: #e0f2fe;
--flash-text: #075985;
box-sizing: border-box;
width: min(40rem, calc(100% - 2rem));
margin: 1rem 0 0;
padding: 0.75rem 1rem;
border-radius: 0.75rem;
background: var(--flash-bg);
color: var(--flash-text);
font-weight: 600;
text-align: center;
}
.flash-success { --flash-bg: #dcfce7; --flash-text: #166534; }
.flash-error { --flash-bg: #fee2e2; --flash-text: #991b1b; }
#message-me-btn {
--btn-bg: #2563eb;
--btn-bg-hover: #1d4ed8;
@@ -140,5 +206,6 @@ main {
@media (prefers-reduced-motion: reduce) {
#message-me-btn,
.site-header a { transition: none; }
.site-header a,
.logout-form button { transition: none; }
}