theater-reader/public/library.js
agent 6240907809 Login button with show-password, skip identical photos on upload
A Přihlásit/Odhlásit button in the top bar replaces logging in via
Přidat hru. The dialog has an eye toggle, says when it is checking,
and keeps the remember box as it was after a wrong password; nothing is
stored until the server accepts it. A remembered password that no
longer works is dropped on load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
2026-11-04 16:15:27 +00:00

39 lines
1.8 KiB
JavaScript

import { api, getPassword, authButton, esc, $ } from "./api.js";
// Old links (/?postava=Lída or /?hra=…) went straight to the reader.
const q = new URLSearchParams(location.search);
if (q.has("hra") || q.has("postava")) location.replace(`read.html${location.search}`);
const fmtDate = (iso) => new Date(iso).toLocaleDateString("cs-CZ", { day: "numeric", month: "numeric", year: "numeric" });
async function main() {
const cfg = await api("config");
await authButton(document.querySelector(".topbar-actions"), { uploads: cfg.uploads, onChange: render });
await render();
}
// Logged in, the list also shows drafts, with buttons to add and edit plays.
async function render() {
const plays = await api("plays");
const loggedIn = Boolean(getPassword());
$("add").hidden = !loggedIn;
if (!plays.length) {
$("plays").innerHTML = `<li class="muted">Zatím tu není žádná hra.${loggedIn ? " Přidejte první tlačítkem nahoře." : ""}</li>`;
return;
}
$("plays").innerHTML = plays.map((p) => {
const badge = p.status === "processing" ? `<span class="badge">přepisuje se ${p.progress ? `${p.progress.done}/${p.progress.total}` : ""}</span>`
: !p.published ? `<span class="badge">koncept</span>` : "";
return `<li class="play-card">
<a class="play-main" href="read.html?hra=${encodeURIComponent(p.id)}">
<span class="play-title">${esc(p.title)} ${badge}</span>
${p.note ? `<span class="play-note">${esc(p.note)}</span>` : ""}
<span class="play-meta">upraveno ${fmtDate(p.updated)}</span>
</a>
${loggedIn ? `<a class="button" href="edit.html?id=${encodeURIComponent(p.id)}">Upravit</a>` : ""}
</li>`;
}).join("");
}
main().catch((err) => { $("plays").innerHTML = `<li class="error">Seznam her se nepodařilo načíst: ${esc(err.message)}</li>`; });