Initial TopDeck: self-hosted ranked favorites
A single Go binary with SQLite that serves a public page of the owner's ranked lists (movies, TV, albums, songs, video games, theater) and a login-gated editor. - Lists of 1–65,535 entries (100 recommended), several per category - Search-to-add via TMDB, TheTVDB, IGDB, Deezer/MusicBrainz, Wikipedia; manual entry as a fallback - Theater entries carry a production (Broadway, tour, …), venue and cast - Artwork cached locally; URL override and uploads - Drag, arrow and type-a-rank reordering; paginated for long lists - 12 theme presets plus custom CSS - First-run setup code or env-provided admin; bcrypt, rate-limited login, CSRF-guarded JSON API - Dockerfile and docker-compose.yml Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
e9a75a968a
53 files changed
+7078
No files matched your search
@@ -0,0 +1,579 @@
|
||||
/* ==========================================================================
|
||||
TopDeck. Colors and fonts come from themes.css.
|
||||
========================================================================== */
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font: 15px/1.5 var(--font);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
main { flex: 1; }
|
||||
img { display: block; max-width: 100%; }
|
||||
a { color: inherit; }
|
||||
button, input, select, textarea { font: inherit; color: inherit; }
|
||||
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; letter-spacing: -0.015em; }
|
||||
p { margin: 0; }
|
||||
code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
|
||||
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
::selection { background: var(--accent); color: var(--accent-text); }
|
||||
|
||||
.icon {
|
||||
width: 1.1em; height: 1.1em; flex: none;
|
||||
fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
|
||||
vertical-align: -0.15em;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
|
||||
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
|
||||
}
|
||||
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--accent); color: var(--accent-text); padding: 8px 14px; border-radius: var(--radius); }
|
||||
.skip-link:focus { left: 8px; }
|
||||
.muted { color: var(--muted); }
|
||||
.small { font-size: 13px; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 24px; }
|
||||
@media (max-width: 640px) { .container { padding: 0 16px; } }
|
||||
|
||||
/* ---------- top bar ---------- */
|
||||
.topbar {
|
||||
position: sticky; top: 0; z-index: 20;
|
||||
background: color-mix(in srgb, var(--bg) 82%, transparent);
|
||||
backdrop-filter: saturate(160%) blur(14px);
|
||||
-webkit-backdrop-filter: saturate(160%) blur(14px);
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
|
||||
}
|
||||
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
|
||||
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 650; min-width: 0; }
|
||||
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.brand-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
|
||||
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
|
||||
.brand-mark .icon { width: 18px; height: 18px; }
|
||||
.topnav { display: flex; align-items: center; gap: 4px; }
|
||||
.topnav a, .topnav-btn {
|
||||
display: inline-flex; align-items: center; gap: 7px;
|
||||
padding: 7px 12px; border-radius: 8px; border: 0; background: none; cursor: pointer;
|
||||
color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500;
|
||||
}
|
||||
.topnav a:hover, .topnav-btn:hover { color: var(--text); background: var(--surface-2); }
|
||||
.topnav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
|
||||
.topnav-form { margin: 0; }
|
||||
@media (max-width: 520px) { .topnav a span { display: none; } }
|
||||
|
||||
/* ---------- footer ---------- */
|
||||
.footer { margin-top: 72px; border-top: 1px solid var(--border); color: var(--faint); font-size: 13px; }
|
||||
.footer-inner { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding-top: 22px; padding-bottom: 28px; }
|
||||
.footer a { color: var(--muted); text-decoration: none; }
|
||||
.footer a:hover { color: var(--accent); }
|
||||
|
||||
/* ---------- buttons ---------- */
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
||||
height: 38px; padding: 0 16px; border-radius: var(--radius);
|
||||
border: 1px solid var(--border); background: var(--surface); color: var(--text);
|
||||
font-size: 14px; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
|
||||
transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
|
||||
}
|
||||
.btn:hover { background: var(--surface-2); }
|
||||
.btn:active { transform: translateY(1px); }
|
||||
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
|
||||
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
|
||||
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
|
||||
.btn--ghost:hover { color: var(--text); background: var(--surface-2); }
|
||||
.btn--danger { color: var(--danger); }
|
||||
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
|
||||
.btn--danger.btn--solid { background: var(--danger); border-color: var(--danger); color: #fff; }
|
||||
.btn--sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 6px; }
|
||||
.btn--block { width: 100%; }
|
||||
.icon-btn {
|
||||
display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
|
||||
border: 0; background: none; color: var(--muted); cursor: pointer;
|
||||
}
|
||||
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
|
||||
.icon-btn:disabled { opacity: 0.35; cursor: default; background: none; }
|
||||
.icon-btn--danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
|
||||
|
||||
/* ---------- chips, badges ---------- */
|
||||
.chip {
|
||||
display: inline-flex; align-items: center; gap: 7px; flex: none;
|
||||
height: 34px; padding: 0 14px; border-radius: 999px;
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
color: var(--muted); font-size: 13.5px; font-weight: 500; text-decoration: none;
|
||||
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.chip:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
|
||||
.badge {
|
||||
display: inline-flex; align-items: center; gap: 5px; width: fit-content;
|
||||
padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
|
||||
background: var(--accent-soft); color: var(--accent);
|
||||
}
|
||||
.badge--warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
|
||||
.badge--muted { background: var(--surface-2); color: var(--muted); }
|
||||
|
||||
/* ---------- profile / home ---------- */
|
||||
.profile { display: flex; align-items: center; gap: 28px; padding-top: 56px; padding-bottom: 28px; }
|
||||
.avatar {
|
||||
flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 50%;
|
||||
background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 45%, var(--bg)));
|
||||
color: var(--accent-text); font-weight: 700;
|
||||
}
|
||||
.avatar img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.avatar--lg { width: 112px; height: 112px; font-size: 44px; box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--border); }
|
||||
.profile-name { font-size: clamp(30px, 5vw, 46px); font-weight: 780; }
|
||||
.profile-tagline { margin-top: 8px; color: var(--muted); font-size: 17px; max-width: 60ch; }
|
||||
.profile-stats { margin-top: 12px; color: var(--faint); font-size: 14px; }
|
||||
.profile-stats strong { color: var(--text); font-weight: 650; }
|
||||
@media (max-width: 640px) {
|
||||
.profile { flex-direction: column; text-align: center; gap: 18px; padding-top: 36px; }
|
||||
.profile-tagline { margin-inline: auto; }
|
||||
.avatar--lg { width: 92px; height: 92px; font-size: 36px; }
|
||||
}
|
||||
|
||||
.jump { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
|
||||
.jump::-webkit-scrollbar { display: none; }
|
||||
@media (max-width: 640px) { .jump { justify-content: flex-start; } }
|
||||
|
||||
.shelf { margin-top: 44px; }
|
||||
.shelf-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
|
||||
.shelf-icon {
|
||||
flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px;
|
||||
background: var(--accent-soft); color: var(--accent);
|
||||
}
|
||||
.shelf-icon .icon { width: 20px; height: 20px; }
|
||||
.shelf-titles { flex: 1; min-width: 0; }
|
||||
.shelf-head h2 { font-size: 22px; font-weight: 720; }
|
||||
.shelf-head h2 a { text-decoration: none; }
|
||||
.shelf-head h2 a:hover { color: var(--accent); }
|
||||
.shelf-desc { color: var(--muted); font-size: 14px; margin-top: 2px; }
|
||||
.see-all {
|
||||
display: inline-flex; align-items: center; gap: 6px; flex: none;
|
||||
color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 550;
|
||||
padding: 6px 10px; border-radius: 8px;
|
||||
}
|
||||
.see-all:hover { color: var(--accent); background: var(--accent-soft); }
|
||||
|
||||
/* ---------- ranked items: grid ---------- */
|
||||
.items { list-style: none; margin: 0; padding: 0; }
|
||||
.items--grid { display: grid; gap: 22px 18px; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
|
||||
.items--grid.aspect-square { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
|
||||
@media (max-width: 640px) {
|
||||
.items--grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 16px 12px; }
|
||||
.items--grid.aspect-square { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
|
||||
}
|
||||
.item-btn {
|
||||
all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px;
|
||||
width: 100%; cursor: pointer; border-radius: var(--radius-art);
|
||||
}
|
||||
.item-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
|
||||
.item-art {
|
||||
position: relative; display: block; overflow: hidden; aspect-ratio: 2 / 3;
|
||||
border-radius: var(--radius-art); background: var(--surface-2);
|
||||
box-shadow: 0 1px 0 color-mix(in srgb, var(--text) 6%, transparent) inset, 0 6px 18px rgba(0, 0, 0, 0.18);
|
||||
transition: transform 0.25s cubic-bezier(.2,.8,.2,1), box-shadow 0.25s;
|
||||
}
|
||||
.aspect-square .item-art { aspect-ratio: 1; }
|
||||
.item-art img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.item-btn:hover .item-art { transform: translateY(-4px); box-shadow: var(--shadow); }
|
||||
.art-fallback {
|
||||
position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint);
|
||||
background: linear-gradient(160deg, var(--surface-2), var(--surface));
|
||||
}
|
||||
.art-fallback .icon { width: 34%; height: 34%; stroke-width: 1.4; }
|
||||
.rank-badge {
|
||||
position: absolute; left: 8px; top: 8px; min-width: 28px; height: 28px; padding: 0 8px;
|
||||
display: grid; place-items: center; border-radius: 8px;
|
||||
background: rgba(10, 10, 14, 0.72); color: #fff;
|
||||
backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
|
||||
font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.item--top1 .rank-badge { background: var(--gold); color: #1b1405; }
|
||||
.item--top2 .rank-badge { background: var(--silver); color: #14171d; }
|
||||
.item--top3 .rank-badge { background: var(--bronze); color: #1d1008; }
|
||||
.item-rank { display: none; }
|
||||
.item-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
||||
.item-title { font-weight: 620; font-size: 14.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.item-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.dot { margin: 0 6px; color: var(--faint); }
|
||||
.items--grid .item-note { display: none; }
|
||||
.item-tags { display: flex; align-items: center; gap: 8px; margin-top: 3px; min-width: 0; }
|
||||
.item-tags .badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: inline-block; }
|
||||
.item-year { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; flex: none; }
|
||||
|
||||
/* ---------- ranked items: rows ---------- */
|
||||
.items--rows { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
|
||||
.items--rows .item { border-bottom: 1px solid var(--border); }
|
||||
.items--rows .item-btn {
|
||||
flex-direction: row; align-items: center; gap: 18px; padding: 12px 10px; border-radius: 0;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.items--rows .item-btn:hover { background: var(--surface); }
|
||||
.items--rows .item-btn:hover .item-art { transform: none; }
|
||||
.items--rows .item-art { order: 2; width: 58px; flex: none; border-radius: calc(var(--radius-art) * 0.7); box-shadow: none; }
|
||||
.items--rows .rank-badge { display: none; }
|
||||
.items--rows .item-rank {
|
||||
order: 1; display: block; width: 3.2ch; flex: none; text-align: right;
|
||||
font: 700 22px/1 var(--font-display); color: var(--faint); font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.items--rows .item--top1 .item-rank { color: var(--gold); }
|
||||
.items--rows .item--top2 .item-rank { color: var(--silver); }
|
||||
.items--rows .item--top3 .item-rank { color: var(--bronze); }
|
||||
.items--rows .item-body { order: 3; flex: 1; }
|
||||
.items--rows .item-title { font-size: 16px; -webkit-line-clamp: 1; }
|
||||
.items--rows .item-note { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
|
||||
@media (min-width: 900px) {
|
||||
.page-home .items--rows { display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; border-top: 0; }
|
||||
.page-home .items--rows .item:nth-child(-n+2) { border-top: 1px solid var(--border); }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.items--rows .item-btn { gap: 12px; padding: 10px 4px; }
|
||||
.items--rows .item-art { width: 48px; }
|
||||
.items--rows .item-rank { font-size: 18px; }
|
||||
}
|
||||
|
||||
/* ---------- list page ---------- */
|
||||
.list-hero { position: relative; overflow: hidden; padding: 28px 0 34px; border-bottom: 1px solid var(--border); }
|
||||
.list-hero-backdrop { position: absolute; inset: 0; z-index: 0; }
|
||||
.list-hero-backdrop img {
|
||||
width: 100%; height: 100%; object-fit: cover; transform: scale(1.3);
|
||||
filter: blur(60px) saturate(1.4); opacity: 0.35;
|
||||
}
|
||||
.list-hero-backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 0%, var(--bg) 100%); }
|
||||
.list-hero-inner { position: relative; z-index: 1; }
|
||||
.back-link {
|
||||
display: inline-flex; align-items: center; gap: 6px; margin-bottom: 22px;
|
||||
color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500;
|
||||
}
|
||||
.back-link:hover { color: var(--text); }
|
||||
.list-hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
|
||||
.eyebrow { display: inline-flex; align-items: center; gap: 7px; color: var(--accent); font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; }
|
||||
.list-title { font-size: clamp(30px, 5vw, 52px); font-weight: 800; margin-top: 8px; }
|
||||
.list-desc { color: var(--muted); font-size: 16px; margin-top: 10px; max-width: 70ch; }
|
||||
.list-meta { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; font-weight: 550; }
|
||||
.list-actions { display: flex; align-items: center; gap: 10px; }
|
||||
.list-body { padding-top: 30px; }
|
||||
|
||||
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: calc(var(--radius) + 2px); background: var(--surface); border: 1px solid var(--border); }
|
||||
.segmented button { display: grid; place-items: center; width: 34px; height: 30px; border: 0; border-radius: calc(var(--radius) - 2px); background: none; color: var(--muted); cursor: pointer; }
|
||||
.segmented button:hover { color: var(--text); }
|
||||
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
|
||||
|
||||
.pager { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 40px; flex-wrap: wrap; }
|
||||
.pager:empty { display: none; }
|
||||
.pager-btn {
|
||||
display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 10px;
|
||||
border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
|
||||
text-decoration: none; font-size: 14px; font-weight: 550; font-variant-numeric: tabular-nums; cursor: pointer; color: var(--text);
|
||||
}
|
||||
.pager-btn:hover { border-color: var(--accent); }
|
||||
.pager-btn.is-current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||
.pager-gap { color: var(--faint); padding: 0 4px; }
|
||||
|
||||
/* ---------- empty / error ---------- */
|
||||
.empty { text-align: center; padding-top: 80px; padding-bottom: 40px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
|
||||
.empty-art { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); margin-bottom: 10px; }
|
||||
.empty-art .icon { width: 32px; height: 32px; }
|
||||
.empty h1, .empty h2 { font-size: 26px; }
|
||||
.empty p { color: var(--muted); max-width: 46ch; }
|
||||
.empty .btn { margin-top: 14px; }
|
||||
.error-code { font: 800 64px/1 var(--font-display); color: var(--accent); }
|
||||
|
||||
/* ---------- dialogs ---------- */
|
||||
dialog {
|
||||
padding: 0; border: 1px solid var(--border); border-radius: calc(var(--radius) + 6px);
|
||||
background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
|
||||
max-width: min(640px, calc(100vw - 32px)); width: 100%; max-height: calc(100dvh - 48px);
|
||||
}
|
||||
dialog::backdrop { background: rgba(5, 6, 10, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
|
||||
dialog[open] { animation: pop 0.18s cubic-bezier(.2,.8,.2,1); }
|
||||
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
|
||||
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
|
||||
.dialog-head h2 { font-size: 19px; font-weight: 700; }
|
||||
.dialog-body { padding: 18px 20px; }
|
||||
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; flex-wrap: wrap; }
|
||||
.dialog-foot .spacer { flex: 1; }
|
||||
|
||||
.item-dialog { max-width: min(860px, calc(100vw - 32px)); overflow: hidden; }
|
||||
.item-dialog-inner { display: grid; grid-template-columns: minmax(200px, 320px) 1fr; max-height: calc(100dvh - 48px); }
|
||||
.item-dialog .dlg-art { position: relative; background: var(--surface-2); }
|
||||
.item-dialog .dlg-art img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.item-dialog .dlg-art .art-fallback .icon { width: 30%; height: 30%; }
|
||||
.item-dialog.is-square .item-dialog-inner { grid-template-columns: minmax(220px, 360px) 1fr; }
|
||||
.item-dialog.is-square .dlg-art { aspect-ratio: 1; align-self: start; }
|
||||
.dlg-body { position: relative; padding: 28px 28px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
|
||||
.dlg-close { position: absolute; top: 10px; right: 10px; }
|
||||
.dlg-rank { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 550; padding-right: 36px; }
|
||||
.dlg-rank strong { font: 800 30px/1 var(--font-display); color: var(--accent); }
|
||||
.dlg-rank.top1 strong { color: var(--gold); }
|
||||
.dlg-rank.top2 strong { color: var(--silver); }
|
||||
.dlg-rank.top3 strong { color: var(--bronze); }
|
||||
.dlg-title { font-size: 28px; font-weight: 780; }
|
||||
.dlg-sub { color: var(--muted); font-size: 15px; margin-top: -4px; }
|
||||
.dlg-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 4px 0 0; font-size: 14px; }
|
||||
.dlg-meta dt { color: var(--faint); }
|
||||
.dlg-meta dd { margin: 0; }
|
||||
.dlg-note {
|
||||
margin: 4px 0 0; padding: 14px 16px; border-left: 3px solid var(--accent);
|
||||
background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0;
|
||||
font-size: 15px; white-space: pre-line;
|
||||
}
|
||||
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 12px; flex-wrap: wrap; }
|
||||
.dlg-nav { margin-left: auto; display: flex; gap: 4px; }
|
||||
@media (max-width: 680px) {
|
||||
.item-dialog-inner, .item-dialog.is-square .item-dialog-inner { grid-template-columns: 1fr; overflow-y: auto; }
|
||||
.item-dialog .dlg-art { max-height: 46vh; aspect-ratio: auto; }
|
||||
.item-dialog .dlg-art img { max-height: 46vh; object-fit: contain; background: var(--surface-2); }
|
||||
.item-dialog .dlg-art .art-fallback { position: static; height: 180px; }
|
||||
.dlg-body { overflow: visible; padding: 22px 20px 20px; }
|
||||
.dlg-title { font-size: 23px; }
|
||||
}
|
||||
|
||||
/* ---------- forms ---------- */
|
||||
.stack { display: flex; flex-direction: column; gap: 16px; }
|
||||
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
||||
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
|
||||
.field-hint { font-size: 12.5px; color: var(--faint); }
|
||||
.field-hint.is-warn { color: var(--warn); }
|
||||
.field-hint.is-error { color: var(--danger); }
|
||||
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
|
||||
width: 100%; height: 40px; padding: 0 12px;
|
||||
background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
|
||||
textarea.code { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 220px; tab-size: 2; }
|
||||
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
|
||||
input::placeholder, textarea::placeholder { color: var(--faint); }
|
||||
input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
|
||||
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
|
||||
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
|
||||
.input-group { display: flex; gap: 8px; }
|
||||
.input-group > input { flex: 1; }
|
||||
|
||||
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 14px; }
|
||||
.alert .icon { margin-top: 2px; }
|
||||
.alert--error { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
|
||||
.alert--info { background: var(--accent-soft); color: var(--text); }
|
||||
.alert--warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); }
|
||||
|
||||
/* ---------- auth ---------- */
|
||||
.page-auth main { display: grid; place-items: center; padding: 48px 16px; }
|
||||
.auth-card {
|
||||
width: 100%; max-width: 400px; padding: 34px 30px 26px;
|
||||
background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 8px);
|
||||
box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
|
||||
}
|
||||
.auth-card h1 { font-size: 26px; }
|
||||
.auth-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
|
||||
.auth-mark .icon { width: 22px; height: 22px; }
|
||||
.auth-back { display: inline-flex; align-items: center; gap: 6px; justify-content: center; color: var(--faint); font-size: 13px; text-decoration: none; margin-top: 4px; }
|
||||
.auth-back:hover { color: var(--text); }
|
||||
|
||||
/* ---------- toasts ---------- */
|
||||
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
|
||||
.toast {
|
||||
display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px;
|
||||
background: var(--text); color: var(--bg); font-size: 14px; font-weight: 550; box-shadow: var(--shadow);
|
||||
animation: toast-in 0.2s ease-out; pointer-events: auto;
|
||||
}
|
||||
.toast--error { background: var(--danger); color: #fff; }
|
||||
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s; }
|
||||
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
|
||||
|
||||
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.7s linear infinite; flex: none; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* ==========================================================================
|
||||
Admin
|
||||
========================================================================== */
|
||||
.admin { padding-top: 32px; }
|
||||
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
|
||||
.admin-head h1 { font-size: 30px; font-weight: 780; }
|
||||
.admin-head p { margin-top: 4px; }
|
||||
.admin-head-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
|
||||
.admin-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
.admin .back-link { margin-bottom: 14px; }
|
||||
|
||||
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px); padding: 18px; }
|
||||
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
|
||||
.panel-head h2 { font-size: 17px; font-weight: 700; }
|
||||
|
||||
.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: -8px 0 24px; }
|
||||
.meter span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.3s; }
|
||||
|
||||
/* list dashboard */
|
||||
.admin-lists { display: flex; flex-direction: column; gap: 10px; }
|
||||
.list-card {
|
||||
display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 8px;
|
||||
background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px);
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
.list-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
|
||||
.list-card-main { flex: 1; min-width: 0; text-decoration: none; display: flex; align-items: center; gap: 14px; }
|
||||
.list-card-covers { display: flex; flex: none; }
|
||||
.list-card-covers span { width: 34px; height: 48px; border-radius: 5px; background: var(--surface-2) center / cover; border: 2px solid var(--surface); margin-left: -14px; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
|
||||
.list-card-covers span:first-child { margin-left: 0; }
|
||||
.list-card-covers.is-square span { height: 34px; }
|
||||
.list-card-title { display: block; font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.list-card-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-top: 2px; flex-wrap: wrap; }
|
||||
.list-card-bar { width: 80px; height: 4px; border-radius: 9px; background: var(--surface-2); overflow: hidden; }
|
||||
.list-card-bar span { display: block; height: 100%; background: var(--accent); }
|
||||
.list-card-actions { display: flex; gap: 2px; }
|
||||
|
||||
.onboard { text-align: center; padding: 48px 20px; border: 1px dashed var(--border); border-radius: calc(var(--radius) + 6px); }
|
||||
.onboard h2 { font-size: 22px; margin-bottom: 6px; }
|
||||
.onboard p { color: var(--muted); }
|
||||
.quick-cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 24px; }
|
||||
|
||||
.cat-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
||||
@media (max-width: 480px) { .cat-picker { grid-template-columns: repeat(2, 1fr); } }
|
||||
.cat-option { position: relative; }
|
||||
.cat-option input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
.cat-option span, .quick-cats button {
|
||||
display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px;
|
||||
border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
|
||||
font-size: 13.5px; font-weight: 550; cursor: pointer; text-align: center; color: var(--text);
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.cat-option .icon, .quick-cats .icon { width: 22px; height: 22px; color: var(--accent); }
|
||||
.cat-option span:hover, .quick-cats button:hover { border-color: var(--accent); }
|
||||
.cat-option input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
|
||||
.cat-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
.cat-option input:disabled + span { opacity: 0.45; cursor: not-allowed; }
|
||||
.size-chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.size-chips button { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 13px; font-weight: 600; }
|
||||
.size-chips button:hover { border-color: var(--accent); }
|
||||
.size-chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||
|
||||
/* list editor */
|
||||
.editor { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 20px; align-items: start; }
|
||||
.editor-search { position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; gap: 12px; }
|
||||
.editor-search .panel-head { margin-bottom: 0; }
|
||||
@media (max-width: 900px) {
|
||||
.editor { grid-template-columns: 1fr; }
|
||||
.editor-search { position: static; max-height: none; }
|
||||
}
|
||||
.search-bar { position: relative; display: flex; align-items: center; }
|
||||
.search-bar > .icon { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }
|
||||
.search-bar input { padding-left: 38px !important; padding-right: 38px !important; }
|
||||
.search-bar .spinner { position: absolute; right: 12px; }
|
||||
.search-results { overflow-y: auto; margin: 0 -8px; padding: 0 8px; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
|
||||
.search-results:empty { display: none; }
|
||||
.search-msg { color: var(--muted); font-size: 14px; padding: 8px 2px; }
|
||||
.result {
|
||||
display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
|
||||
padding: 8px; border-radius: var(--radius); transition: background 0.12s;
|
||||
}
|
||||
.result:hover { background: var(--surface-2); }
|
||||
.result-art { width: 48px; aspect-ratio: 2 / 3; border-radius: 5px; background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center; color: var(--faint); overflow: hidden; }
|
||||
.result-art img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.is-square .result-art { aspect-ratio: 1; }
|
||||
.result-title { font-weight: 600; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.result-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.result-overview { color: var(--faint); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
|
||||
.result-added { font-size: 12px; font-weight: 600; color: var(--success); display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
|
||||
|
||||
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
|
||||
.rank-row {
|
||||
display: grid; grid-template-columns: 28px 64px 44px 1fr auto; align-items: center; gap: 10px;
|
||||
padding: 8px 6px; border-radius: var(--radius); background: var(--surface);
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
|
||||
}
|
||||
.rank-row:hover { background: var(--surface-2); }
|
||||
.rank-row.is-dragging { position: relative; z-index: 5; box-shadow: var(--shadow); background: var(--surface-2); border-color: var(--accent); opacity: 0.96; }
|
||||
.rank-row.is-placeholder { background: var(--accent-soft); border: 1px dashed var(--accent); }
|
||||
.rank-row.is-placeholder > * { visibility: hidden; }
|
||||
.rank-row.is-flash { animation: flash 1.2s ease-out; }
|
||||
@keyframes flash { from { background: var(--accent-soft); } }
|
||||
.drag-handle { display: grid; place-items: center; width: 28px; height: 36px; color: var(--faint); cursor: grab; touch-action: none; border: 0; background: none; border-radius: 6px; }
|
||||
.drag-handle:hover { color: var(--text); background: var(--surface-2); }
|
||||
.dragging-active, .dragging-active * { cursor: grabbing !important; user-select: none; }
|
||||
.rank-input {
|
||||
width: 64px !important; height: 34px !important; padding: 0 6px !important; text-align: center;
|
||||
font-weight: 750; font-variant-numeric: tabular-nums; background: transparent !important; border-color: transparent !important;
|
||||
}
|
||||
.rank-input:hover { border-color: var(--border) !important; }
|
||||
.rank-input:focus { background: var(--bg) !important; border-color: var(--accent) !important; }
|
||||
.rank-row .result-art { width: 44px; }
|
||||
.rank-row-body { min-width: 0; }
|
||||
.rank-row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.rank-row-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 8px; align-items: center; }
|
||||
.rank-row-actions { display: flex; gap: 0; }
|
||||
@media (max-width: 640px) {
|
||||
.rank-row { grid-template-columns: 24px 50px 38px 1fr auto; gap: 6px; }
|
||||
.rank-row .result-art { width: 38px; }
|
||||
.rank-input { width: 50px !important; }
|
||||
.rank-row-actions .hide-sm { display: none; }
|
||||
}
|
||||
.rank-empty { text-align: center; padding: 40px 16px; color: var(--muted); }
|
||||
|
||||
/* item editor dialog */
|
||||
.art-edit { display: grid; grid-template-columns: 110px 1fr; gap: 16px; align-items: start; }
|
||||
.art-edit .result-art { width: 110px; }
|
||||
.art-edit-actions { display: flex; flex-direction: column; gap: 8px; }
|
||||
.art-edit-actions .row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
@media (max-width: 480px) { .art-edit { grid-template-columns: 80px 1fr; } .art-edit .result-art { width: 80px; } }
|
||||
|
||||
/* settings */
|
||||
.settings { display: grid; grid-template-columns: 200px 1fr; gap: 32px; align-items: start; }
|
||||
.settings-nav { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 2px; }
|
||||
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; font-size: 14px; }
|
||||
.settings-nav a:hover { background: var(--surface); color: var(--text); }
|
||||
.settings-body { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
|
||||
.settings-section { scroll-margin-top: 80px; }
|
||||
.settings-section > .panel { display: flex; flex-direction: column; gap: 18px; }
|
||||
.settings-section h2 { font-size: 20px; margin-bottom: 4px; }
|
||||
.settings-section .section-desc { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
|
||||
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
@media (max-width: 860px) {
|
||||
.settings { grid-template-columns: 1fr; gap: 16px; }
|
||||
.settings-nav { position: static; flex-direction: row; overflow-x: auto; }
|
||||
}
|
||||
.avatar-edit { display: flex; align-items: center; gap: 16px; }
|
||||
.avatar-edit .avatar { width: 72px; height: 72px; font-size: 28px; }
|
||||
|
||||
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
|
||||
.theme-card { position: relative; cursor: pointer; }
|
||||
.theme-card input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
.theme-swatch {
|
||||
display: block; border-radius: var(--radius); overflow: hidden; border: 2px solid var(--border);
|
||||
background: var(--bg); color: var(--text); transition: border-color 0.15s, transform 0.15s;
|
||||
}
|
||||
.theme-card:hover .theme-swatch { transform: translateY(-2px); }
|
||||
.theme-card input:checked + .theme-swatch { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
|
||||
.theme-card input:focus-visible + .theme-swatch { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
.theme-preview { display: flex; gap: 6px; padding: 12px; background: var(--bg); }
|
||||
.theme-preview i { flex: 1; aspect-ratio: 2 / 3; border-radius: 4px; background: var(--surface-2); }
|
||||
.theme-preview i:first-child { background: var(--accent); }
|
||||
.theme-name { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface); font-size: 13px; font-weight: 600; }
|
||||
.theme-kind { color: var(--muted); font-size: 11px; font-weight: 500; }
|
||||
|
||||
.integration { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
|
||||
.integration-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
|
||||
.integration-head h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
|
||||
.integration-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
|
||||
.integration .field-hint a { color: var(--accent); }
|
||||
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
|
||||
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
|
||||
.status.is-ok { color: var(--success); }
|
||||
.status.is-ok::before { background: var(--success); }
|
||||
.status.is-off { color: var(--faint); }
|
||||
.test-result { font-size: 13px; }
|
||||
.test-result.is-ok { color: var(--success); }
|
||||
.test-result.is-error { color: var(--danger); }
|
||||
.radio-cards { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
.radio-cards label { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 14px; }
|
||||
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
|
||||
.radio-cards input { accent-color: var(--accent); margin: 0; }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* TopDeck theme presets.
|
||||
*
|
||||
* Every color on the site comes from these variables, so a custom theme only
|
||||
* needs to override them (Settings → Appearance → Custom CSS), e.g.
|
||||
*
|
||||
* :root, [data-theme] { --accent: #ff4f81; --bg: #120d14; }
|
||||
*/
|
||||
|
||||
:root,
|
||||
[data-theme="midnight"] {
|
||||
color-scheme: dark;
|
||||
--bg: #0f1117;
|
||||
--surface: #171a22;
|
||||
--surface-2: #1f232e;
|
||||
--border: #2a2f3c;
|
||||
--text: #eceef4;
|
||||
--muted: #9aa1b2;
|
||||
--faint: #636a7c;
|
||||
--accent: #8b7dff;
|
||||
--accent-text: #ffffff;
|
||||
--accent-soft: rgba(139, 125, 255, 0.14);
|
||||
--danger: #ff6b7a;
|
||||
--success: #4fd1a1;
|
||||
--warn: #f5b84b;
|
||||
--gold: #f5c451;
|
||||
--silver: #cfd6e4;
|
||||
--bronze: #d99a6c;
|
||||
--shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
|
||||
--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
--font-display: var(--font);
|
||||
--radius: 10px;
|
||||
--radius-art: 8px;
|
||||
}
|
||||
|
||||
[data-theme="obsidian"] {
|
||||
color-scheme: dark;
|
||||
--bg: #000000;
|
||||
--surface: #0c0c0c;
|
||||
--surface-2: #161616;
|
||||
--border: #262626;
|
||||
--text: #f5f5f5;
|
||||
--muted: #a3a3a3;
|
||||
--faint: #5f5f5f;
|
||||
--accent: #f5f5f5;
|
||||
--accent-text: #000000;
|
||||
--accent-soft: rgba(255, 255, 255, 0.09);
|
||||
--shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
[data-theme="nord"] {
|
||||
color-scheme: dark;
|
||||
--bg: #242933;
|
||||
--surface: #2e3440;
|
||||
--surface-2: #3b4252;
|
||||
--border: #434c5e;
|
||||
--text: #eceff4;
|
||||
--muted: #b4bccb;
|
||||
--faint: #7b8598;
|
||||
--accent: #88c0d0;
|
||||
--accent-text: #1f242d;
|
||||
--accent-soft: rgba(136, 192, 208, 0.15);
|
||||
--danger: #bf616a;
|
||||
--success: #a3be8c;
|
||||
--warn: #ebcb8b;
|
||||
}
|
||||
|
||||
[data-theme="dracula"] {
|
||||
color-scheme: dark;
|
||||
--bg: #21222c;
|
||||
--surface: #282a36;
|
||||
--surface-2: #343746;
|
||||
--border: #44475a;
|
||||
--text: #f8f8f2;
|
||||
--muted: #b6b9cf;
|
||||
--faint: #6272a4;
|
||||
--accent: #ff79c6;
|
||||
--accent-text: #21222c;
|
||||
--accent-soft: rgba(255, 121, 198, 0.14);
|
||||
--danger: #ff5555;
|
||||
--success: #50fa7b;
|
||||
--warn: #f1fa8c;
|
||||
}
|
||||
|
||||
[data-theme="mocha"] {
|
||||
color-scheme: dark;
|
||||
--bg: #181825;
|
||||
--surface: #1e1e2e;
|
||||
--surface-2: #313244;
|
||||
--border: #45475a;
|
||||
--text: #cdd6f4;
|
||||
--muted: #a6adc8;
|
||||
--faint: #6c7086;
|
||||
--accent: #cba6f7;
|
||||
--accent-text: #1e1e2e;
|
||||
--accent-soft: rgba(203, 166, 247, 0.14);
|
||||
--danger: #f38ba8;
|
||||
--success: #a6e3a1;
|
||||
--warn: #f9e2af;
|
||||
}
|
||||
|
||||
[data-theme="rose-pine"] {
|
||||
color-scheme: dark;
|
||||
--bg: #191724;
|
||||
--surface: #1f1d2e;
|
||||
--surface-2: #26233a;
|
||||
--border: #393552;
|
||||
--text: #e0def4;
|
||||
--muted: #a8a4c4;
|
||||
--faint: #6e6a86;
|
||||
--accent: #ebbcba;
|
||||
--accent-text: #191724;
|
||||
--accent-soft: rgba(235, 188, 186, 0.14);
|
||||
--danger: #eb6f92;
|
||||
--success: #9ccfd8;
|
||||
--warn: #f6c177;
|
||||
}
|
||||
|
||||
[data-theme="gruvbox"] {
|
||||
color-scheme: dark;
|
||||
--bg: #1d2021;
|
||||
--surface: #282828;
|
||||
--surface-2: #32302f;
|
||||
--border: #45403d;
|
||||
--text: #ebdbb2;
|
||||
--muted: #bdae93;
|
||||
--faint: #7c6f64;
|
||||
--accent: #fe8019;
|
||||
--accent-text: #1d2021;
|
||||
--accent-soft: rgba(254, 128, 25, 0.14);
|
||||
--danger: #fb4934;
|
||||
--success: #b8bb26;
|
||||
--warn: #fabd2f;
|
||||
}
|
||||
|
||||
[data-theme="forest"] {
|
||||
color-scheme: dark;
|
||||
--bg: #0f1612;
|
||||
--surface: #151f19;
|
||||
--surface-2: #1c2921;
|
||||
--border: #29392f;
|
||||
--text: #e4efe7;
|
||||
--muted: #9fb5a6;
|
||||
--faint: #62786a;
|
||||
--accent: #7fd49b;
|
||||
--accent-text: #0f1612;
|
||||
--accent-soft: rgba(127, 212, 155, 0.13);
|
||||
}
|
||||
|
||||
[data-theme="synthwave"] {
|
||||
color-scheme: dark;
|
||||
--bg: #140b24;
|
||||
--surface: #1d1133;
|
||||
--surface-2: #281846;
|
||||
--border: #3b2663;
|
||||
--text: #f4eaff;
|
||||
--muted: #bca8dc;
|
||||
--faint: #7a649e;
|
||||
--accent: #ff4fd8;
|
||||
--accent-text: #140b24;
|
||||
--accent-soft: rgba(255, 79, 216, 0.15);
|
||||
--warn: #ffd166;
|
||||
--success: #36f1cd;
|
||||
--shadow: 0 10px 40px rgba(255, 79, 216, 0.12);
|
||||
}
|
||||
|
||||
[data-theme="daylight"] {
|
||||
color-scheme: light;
|
||||
--bg: #f6f7f9;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #eef0f4;
|
||||
--border: #e0e3ea;
|
||||
--text: #15171c;
|
||||
--muted: #5d6475;
|
||||
--faint: #9299a8;
|
||||
--accent: #5b4ef0;
|
||||
--accent-text: #ffffff;
|
||||
--accent-soft: rgba(91, 78, 240, 0.1);
|
||||
--danger: #d93a4b;
|
||||
--success: #17915f;
|
||||
--warn: #b7791f;
|
||||
--gold: #d69e1a;
|
||||
--silver: #8f98a8;
|
||||
--bronze: #b8734a;
|
||||
--shadow: 0 10px 30px rgba(20, 24, 40, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="paper"] {
|
||||
color-scheme: light;
|
||||
--bg: #f4efe6;
|
||||
--surface: #fbf8f2;
|
||||
--surface-2: #ece5d8;
|
||||
--border: #ddd3c2;
|
||||
--text: #2b2520;
|
||||
--muted: #6e6457;
|
||||
--faint: #a2978a;
|
||||
--accent: #b5452f;
|
||||
--accent-text: #fbf8f2;
|
||||
--accent-soft: rgba(181, 69, 47, 0.1);
|
||||
--danger: #b5452f;
|
||||
--success: #3f7d4f;
|
||||
--warn: #a8741a;
|
||||
--gold: #b88a1b;
|
||||
--silver: #8a8a8a;
|
||||
--bronze: #a0623b;
|
||||
--shadow: 0 10px 30px rgba(60, 40, 20, 0.1);
|
||||
--font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
|
||||
--radius: 4px;
|
||||
--radius-art: 3px;
|
||||
}
|
||||
|
||||
[data-theme="latte"] {
|
||||
color-scheme: light;
|
||||
--bg: #eff1f5;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #e6e9ef;
|
||||
--border: #ccd0da;
|
||||
--text: #4c4f69;
|
||||
--muted: #6c6f85;
|
||||
--faint: #9ca0b0;
|
||||
--accent: #8839ef;
|
||||
--accent-text: #ffffff;
|
||||
--accent-soft: rgba(136, 57, 239, 0.1);
|
||||
--danger: #d20f39;
|
||||
--success: #40a02b;
|
||||
--warn: #df8e1d;
|
||||
--gold: #df8e1d;
|
||||
--silver: #8c8fa1;
|
||||
--bronze: #c06d3a;
|
||||
--shadow: 0 10px 30px rgba(76, 79, 105, 0.12);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect x="9" y="3" width="19" height="24" rx="4" fill="#6d5dfc" opacity=".45"/><rect x="4" y="6" width="19" height="24" rx="4" fill="#8b7dff"/><path d="m13.5 11.5 1.9 3.9 4.3.6-3.1 3 .7 4.3-3.8-2-3.8 2 .7-4.3-3.1-3 4.3-.6z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 303 B |
@@ -0,0 +1,41 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="deck" viewBox="0 0 24 24"><rect x="3" y="6" width="13" height="16" rx="2"/><path d="M7 6V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-3"/><path d="m9.5 10.4 1 2.1 2.3.3-1.7 1.6.4 2.3-2-1.1-2 1.1.4-2.3-1.7-1.6 2.3-.3z"/></symbol>
|
||||
<symbol id="film" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 3v18M3 7.5h4M3 12h18M3 16.5h4M17 3v18M17 7.5h4M17 16.5h4"/></symbol>
|
||||
<symbol id="tv" viewBox="0 0 24 24"><rect width="20" height="15" x="2" y="7" rx="2"/><path d="m17 2-5 5-5-5"/></symbol>
|
||||
<symbol id="disc" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="3"/><path d="M12 5a7 7 0 0 0-7 7"/></symbol>
|
||||
<symbol id="music" viewBox="0 0 24 24"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></symbol>
|
||||
<symbol id="gamepad" viewBox="0 0 24 24"><path d="M6 12h4M8 10v4M15 13h.01M18 11h.01"/><rect width="20" height="12" x="2" y="6" rx="4"/></symbol>
|
||||
<symbol id="masks" viewBox="0 0 24 24"><path d="M2 4.5c0-.8.6-1.4 1.4-1.3C5 3.4 7 3.4 8.6 3.1c.8-.1 1.4.5 1.4 1.3V9c0 3.3-1.8 6-4 6s-4-2.7-4-6z"/><path d="M4.5 7.5h.01M7.5 7.5h.01M4.8 11.2c.7-.5 1.7-.5 2.4 0"/><path d="M14 9.6c0-.8.6-1.4 1.4-1.3 1.6.3 3.6.3 5.2 0 .8-.1 1.4.5 1.4 1.3V14c0 3.3-1.8 6-4 6s-4-2.7-4-6z"/><path d="M16.5 12.5h.01M19.5 12.5h.01M16.8 15.6c.7.5 1.7.5 2.4 0"/><path d="M10 12.5c.9.7 2.3.8 4 .3"/></symbol>
|
||||
<symbol id="grip" viewBox="0 0 24 24"><circle cx="9" cy="6" r="1"/><circle cx="9" cy="12" r="1"/><circle cx="9" cy="18" r="1"/><circle cx="15" cy="6" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="18" r="1"/></symbol>
|
||||
<symbol id="pencil" viewBox="0 0 24 24"><path d="M17 3a2.85 2.85 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></symbol>
|
||||
<symbol id="trash" viewBox="0 0 24 24"><path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6"/></symbol>
|
||||
<symbol id="plus" viewBox="0 0 24 24"><path d="M5 12h14M12 5v14"/></symbol>
|
||||
<symbol id="search" viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></symbol>
|
||||
<symbol id="external" viewBox="0 0 24 24"><path d="M15 3h6v6M10 14 21 3M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/></symbol>
|
||||
<symbol id="x" viewBox="0 0 24 24"><path d="M18 6 6 18M6 6l12 12"/></symbol>
|
||||
<symbol id="check" viewBox="0 0 24 24"><path d="M20 6 9 17l-5-5"/></symbol>
|
||||
<symbol id="eye" viewBox="0 0 24 24"><path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></symbol>
|
||||
<symbol id="eye-off" viewBox="0 0 24 24"><path d="M9.9 9.9a3 3 0 1 0 4.2 4.2M10.7 5.1A10.4 10.4 0 0 1 12 5c6.4 0 10 7 10 7a13 13 0 0 1-1.7 2.7M6.6 6.6A13.5 13.5 0 0 0 2 12s3.6 7 10 7a9.7 9.7 0 0 0 5.4-1.6M2 2l20 20"/></symbol>
|
||||
<symbol id="settings" viewBox="0 0 24 24"><path d="M20 7h-9M14 17H5"/><circle cx="17" cy="17" r="3"/><circle cx="7" cy="7" r="3"/></symbol>
|
||||
<symbol id="list" viewBox="0 0 24 24"><path d="M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"/></symbol>
|
||||
<symbol id="rows" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="6" rx="1.5"/><rect x="3" y="14" width="18" height="6" rx="1.5"/></symbol>
|
||||
<symbol id="grid" viewBox="0 0 24 24"><rect width="7" height="7" x="3" y="3" rx="1.5"/><rect width="7" height="7" x="14" y="3" rx="1.5"/><rect width="7" height="7" x="14" y="14" rx="1.5"/><rect width="7" height="7" x="3" y="14" rx="1.5"/></symbol>
|
||||
<symbol id="logout" viewBox="0 0 24 24"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4M16 17l5-5-5-5M21 12H9"/></symbol>
|
||||
<symbol id="upload" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12"/></symbol>
|
||||
<symbol id="image" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/></symbol>
|
||||
<symbol id="arrow-left" viewBox="0 0 24 24"><path d="m12 19-7-7 7-7M19 12H5"/></symbol>
|
||||
<symbol id="arrow-right" viewBox="0 0 24 24"><path d="M5 12h14M12 5l7 7-7 7"/></symbol>
|
||||
<symbol id="chevron-up" viewBox="0 0 24 24"><path d="m18 15-6-6-6 6"/></symbol>
|
||||
<symbol id="chevron-down" viewBox="0 0 24 24"><path d="m6 9 6 6 6-6"/></symbol>
|
||||
<symbol id="chevron-left" viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></symbol>
|
||||
<symbol id="chevron-right" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></symbol>
|
||||
<symbol id="link" viewBox="0 0 24 24"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></symbol>
|
||||
<symbol id="palette" viewBox="0 0 24 24"><path d="M12 2a10 10 0 0 0 0 20c1 0 1.7-.8 1.7-1.7 0-.4-.2-.8-.5-1.1a1.6 1.6 0 0 1 1.3-2.8h2A5.5 5.5 0 0 0 22 11c0-5-4.5-9-10-9Z"/><circle cx="13.5" cy="6.5" r=".8"/><circle cx="17.5" cy="10.5" r=".8"/><circle cx="8.5" cy="7.5" r=".8"/><circle cx="6.5" cy="12.5" r=".8"/></symbol>
|
||||
<symbol id="user" viewBox="0 0 24 24"><circle cx="12" cy="8" r="5"/><path d="M20 21a8 8 0 0 0-16 0"/></symbol>
|
||||
<symbol id="lock" viewBox="0 0 24 24"><rect width="18" height="11" x="3" y="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></symbol>
|
||||
<symbol id="plug" viewBox="0 0 24 24"><path d="M12 22v-5M9 8V2M15 8V2M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"/></symbol>
|
||||
<symbol id="alert" viewBox="0 0 24 24"><path d="m21.7 18-8-14a2 2 0 0 0-3.5 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.7-3ZM12 9v4M12 17h.01"/></symbol>
|
||||
<symbol id="info" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4M12 8h.01"/></symbol>
|
||||
<symbol id="crown" viewBox="0 0 24 24"><path d="M11.6 3.3a.5.5 0 0 1 .8 0l2.9 5.5a1 1 0 0 0 1.5.3l4.4-3.7a.5.5 0 0 1 .8.5l-2.8 10.4a1 1 0 0 1-1 .7H5.8a1 1 0 0 1-1-.7L2 5.9a.5.5 0 0 1 .8-.5l4.4 3.7a1 1 0 0 0 1.5-.3zM5 21h14"/></symbol>
|
||||
<symbol id="refresh" viewBox="0 0 24 24"><path d="M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M8 16H3v5"/></symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.7 KiB |
@@ -0,0 +1,480 @@
|
||||
// List editor: search providers, add entries, rank and edit them.
|
||||
import { h, icon, api, readBoot, toast, confirmDialog, openDialog, dialogHead, debounce, busy, fmt } from "./common.js";
|
||||
import { sortable } from "./sortable.js";
|
||||
import { openListForm } from "./list-form.js";
|
||||
|
||||
const boot = readBoot();
|
||||
const { categories, limits, productions } = boot;
|
||||
const cat = boot.category;
|
||||
const pageSize = boot.pageSize;
|
||||
let list = boot.list;
|
||||
let items = [];
|
||||
let page = 1;
|
||||
|
||||
const square = cat.aspect === "square";
|
||||
const $ = (sel) => document.querySelector(sel);
|
||||
const rankList = $("[data-rank-list]");
|
||||
const pager = $("[data-pager]");
|
||||
const results = $("[data-results]");
|
||||
const searchForm = $("[data-search]");
|
||||
const searchInput = searchForm.querySelector("input");
|
||||
const spinner = searchForm.querySelector(".spinner");
|
||||
if (square) {
|
||||
rankList.classList.add("is-square");
|
||||
results.classList.add("is-square");
|
||||
}
|
||||
|
||||
// Category-specific extra fields, stored in item.extra.
|
||||
const EXTRA_FIELDS = {
|
||||
movie: [["genres", "Genres"], ["runtime", "Runtime"]],
|
||||
tv: [["genres", "Genres"]],
|
||||
album: [["type", "Type (EP, Live…)"], ["label", "Label"], ["genres", "Genres"]],
|
||||
song: [["album", "Album"], ["length", "Length"]],
|
||||
game: [["platforms", "Platforms"], ["genres", "Genres"]],
|
||||
theater: [["venue", "Venue / Theatre"], ["cast", "Notable cast"]],
|
||||
};
|
||||
|
||||
// ---------- header ----------
|
||||
|
||||
function renderHeader() {
|
||||
document.querySelector("[data-bind=title]").textContent = list.title;
|
||||
document.querySelector("[data-bind=count]").textContent = fmt.format(list.itemCount);
|
||||
document.querySelector("[data-bind=max]").textContent = fmt.format(list.maxItems);
|
||||
document.querySelector("[data-bind=hidden]").textContent = list.visible ? "" : " · Hidden";
|
||||
document.querySelector("[data-bind=public]").href = `/l/${list.slug}`;
|
||||
document.querySelector("[data-bind=meter]").style.width = Math.min(100, (list.itemCount / list.maxItems) * 100) + "%";
|
||||
document.querySelector("[data-bind=provider]").textContent = boot.provider ? `via ${boot.provider}` : "";
|
||||
document.title = `${list.title} · ${document.title.split(" · ").pop()}`;
|
||||
}
|
||||
|
||||
const isFull = () => list.itemCount >= list.maxItems;
|
||||
|
||||
document.querySelector("[data-action=edit-list]").addEventListener("click", () => {
|
||||
openListForm({
|
||||
categories, limits, list,
|
||||
onSaved: (saved) => {
|
||||
list = saved;
|
||||
renderHeader();
|
||||
renderResults(lastResults);
|
||||
toast("List saved");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// ---------- ranked items ----------
|
||||
|
||||
const pages = () => Math.max(1, Math.ceil(list.itemCount / pageSize));
|
||||
|
||||
async function load(p = page, flashId) {
|
||||
page = Math.min(Math.max(1, p), pages());
|
||||
try {
|
||||
items = await api("GET", `/api/lists/${list.id}/items?offset=${(page - 1) * pageSize}&limit=${pageSize}`);
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
return;
|
||||
}
|
||||
renderItems(flashId);
|
||||
}
|
||||
|
||||
function artBox(src, alt = "") {
|
||||
const box = h("span", { class: "result-art" });
|
||||
if (src) {
|
||||
const img = h("img", { src, alt, loading: "lazy", referrerpolicy: "no-referrer" });
|
||||
img.addEventListener("error", () => img.replaceWith(icon(cat.icon)), { once: true });
|
||||
box.append(img);
|
||||
} else {
|
||||
box.append(icon(cat.icon));
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
function row(it) {
|
||||
const rankInput = h("input", {
|
||||
class: "rank-input", type: "number", min: 1, max: list.itemCount, value: it.rank,
|
||||
"aria-label": `Rank of ${it.title}`, inputmode: "numeric",
|
||||
});
|
||||
const commit = () => {
|
||||
const n = Number(rankInput.value);
|
||||
if (!Number.isInteger(n) || n === it.rank) { rankInput.value = it.rank; return; }
|
||||
moveTo(it, Math.min(Math.max(1, n), list.itemCount));
|
||||
};
|
||||
rankInput.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); rankInput.blur(); } });
|
||||
rankInput.addEventListener("change", commit);
|
||||
|
||||
const sub = [it.subtitle, it.year].filter(Boolean).join(" · ");
|
||||
return h("li", { class: "rank-row", "data-id": it.id },
|
||||
h("button", { type: "button", class: "drag-handle", "aria-label": `Drag to reorder ${it.title}, or use arrow keys` }, icon("grip")),
|
||||
rankInput,
|
||||
artBox(it.image ? `/images/${it.image}` : ""),
|
||||
h("div", { class: "rank-row-body" },
|
||||
h("div", { class: "rank-row-title" }, it.title),
|
||||
h("div", { class: "rank-row-sub" },
|
||||
it.extra?.production && h("span", { class: "badge" }, it.extra.production),
|
||||
sub && h("span", {}, sub),
|
||||
it.note && h("span", { title: "Has a note" }, icon("pencil")),
|
||||
),
|
||||
),
|
||||
h("div", { class: "rank-row-actions" },
|
||||
h("button", { type: "button", class: "icon-btn hide-sm", "aria-label": "Move up", title: "Move up", disabled: it.rank === 1, onclick: () => moveTo(it, it.rank - 1) }, icon("chevron-up")),
|
||||
h("button", { type: "button", class: "icon-btn hide-sm", "aria-label": "Move down", title: "Move down", disabled: it.rank === list.itemCount, onclick: () => moveTo(it, it.rank + 1) }, icon("chevron-down")),
|
||||
h("button", { type: "button", class: "icon-btn", "aria-label": `Edit ${it.title}`, title: "Edit", onclick: () => openItemForm({ item: it }) }, icon("pencil")),
|
||||
h("button", { type: "button", class: "icon-btn icon-btn--danger", "aria-label": `Remove ${it.title}`, title: "Remove", onclick: () => removeItem(it) }, icon("trash")),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function renderItems(flashId) {
|
||||
if (!items.length) {
|
||||
rankList.replaceChildren(h("li", { class: "rank-empty" },
|
||||
h("div", { class: "empty-art", style: { margin: "0 auto 12px" } }, icon(cat.icon)),
|
||||
h("p", {}, `No ${cat.label.toLowerCase()} yet. Search on the left to add your first.`)));
|
||||
} else {
|
||||
rankList.replaceChildren(...items.map(row));
|
||||
}
|
||||
if (flashId) {
|
||||
const el = rankList.querySelector(`[data-id="${flashId}"]`);
|
||||
if (el) {
|
||||
el.classList.add("is-flash");
|
||||
el.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
renderPager();
|
||||
}
|
||||
|
||||
function renderPager() {
|
||||
const total = pages();
|
||||
if (total <= 1) { pager.replaceChildren(); return; }
|
||||
const btn = (p, label = String(p), aria) => h("button", {
|
||||
type: "button", class: "pager-btn" + (p === page ? " is-current" : ""), "aria-label": aria,
|
||||
"aria-current": p === page ? "page" : null, onclick: () => load(p),
|
||||
}, label);
|
||||
const nums = [];
|
||||
let last = 0;
|
||||
for (let i = 1; i <= total; i++) {
|
||||
if (i === 1 || i === total || Math.abs(i - page) <= 2) {
|
||||
if (last && i - last > 1) nums.push(h("span", { class: "pager-gap" }, "…"));
|
||||
nums.push(btn(i, `${fmt.format((i - 1) * pageSize + 1)}–${fmt.format(Math.min(i * pageSize, list.itemCount))}`));
|
||||
last = i;
|
||||
}
|
||||
}
|
||||
pager.replaceChildren(...nums);
|
||||
}
|
||||
|
||||
async function moveTo(it, rank) {
|
||||
try {
|
||||
await api("POST", `/api/items/${it.id}/move`, { rank });
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
}
|
||||
const targetPage = Math.ceil(rank / pageSize);
|
||||
await load(targetPage, it.id);
|
||||
}
|
||||
|
||||
sortable(rankList, {
|
||||
onMove: async (el, from, to) => {
|
||||
const id = Number(el.dataset.id);
|
||||
const it = items.find((x) => x.id === id);
|
||||
const rank = (page - 1) * pageSize + to + 1;
|
||||
// Renumber right away so the UI feels instant; the reload confirms.
|
||||
[...rankList.children].forEach((li, i) => {
|
||||
const input = li.querySelector(".rank-input");
|
||||
if (input) input.value = (page - 1) * pageSize + i + 1;
|
||||
});
|
||||
try {
|
||||
await api("POST", `/api/items/${id}/move`, { rank });
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
}
|
||||
await load(page, it?.id);
|
||||
},
|
||||
});
|
||||
|
||||
async function removeItem(it) {
|
||||
const ok = await confirmDialog({
|
||||
title: "Remove from list?",
|
||||
message: `“${it.title}” will be removed from #${it.rank}, and everything below moves up one spot.`,
|
||||
confirm: "Remove",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
try {
|
||||
await api("DELETE", `/api/items/${it.id}`);
|
||||
list.itemCount--;
|
||||
renderHeader();
|
||||
toast(`Removed “${it.title}”`);
|
||||
await load();
|
||||
markResult(it, 0);
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- search ----------
|
||||
|
||||
let lastResults = null;
|
||||
let searchSeq = 0;
|
||||
|
||||
async function search(q) {
|
||||
q = q.trim();
|
||||
if (!q) { renderResults(null); return; }
|
||||
const seq = ++searchSeq;
|
||||
spinner.hidden = false;
|
||||
try {
|
||||
const data = await api("GET", `/api/search?category=${cat.key}&list=${list.id}&q=${encodeURIComponent(q)}`);
|
||||
if (seq !== searchSeq) return;
|
||||
renderResults(data.results);
|
||||
} catch (err) {
|
||||
if (seq !== searchSeq) return;
|
||||
lastResults = null;
|
||||
const needsSetup = err.status === 424;
|
||||
results.replaceChildren(h("div", { class: "alert " + (needsSetup ? "alert--warn" : "alert--error") },
|
||||
icon(needsSetup ? "key" : "alert"),
|
||||
h("div", {}, err.message, needsSetup && h("div", {}, h("a", { href: "/admin/settings#integrations" }, "Open integrations →")))));
|
||||
} finally {
|
||||
if (seq === searchSeq) spinner.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
function resultKey(r) { return `${r.provider}:${r.providerId}`; }
|
||||
|
||||
function markResult(it, rank) {
|
||||
if (!lastResults || !it.provider) return;
|
||||
const r = lastResults.find((x) => x.provider === it.provider && x.providerId === it.providerId);
|
||||
if (r) { r.existingRank = rank; renderResults(lastResults); }
|
||||
}
|
||||
|
||||
function renderResults(res) {
|
||||
lastResults = res;
|
||||
if (res == null) { results.replaceChildren(); return; }
|
||||
if (!res.length) {
|
||||
results.replaceChildren(h("p", { class: "search-msg" }, "No matches. Try another spelling, or add it manually below."));
|
||||
return;
|
||||
}
|
||||
const full = isFull();
|
||||
const nodes = res.map((r) => {
|
||||
const sub = [r.subtitle, r.year, r.extra?.type].filter(Boolean).join(" · ");
|
||||
const action = r.existingRank
|
||||
? h("span", { class: "result-added" }, icon("check"), `#${r.existingRank}`)
|
||||
: h("button", {
|
||||
type: "button", class: "btn btn--sm btn--primary", disabled: full,
|
||||
title: full ? "This list is full" : `Add to #${list.itemCount + 1}`,
|
||||
onclick: (e) => addResult(r, e.currentTarget),
|
||||
}, icon("plus"), "Add");
|
||||
return h("div", { class: "result", "data-key": resultKey(r) },
|
||||
artBox(r.imageUrl, ""),
|
||||
h("div", { style: { minWidth: 0 } },
|
||||
h("div", { class: "result-title" }, r.title),
|
||||
sub && h("div", { class: "result-sub" }, sub),
|
||||
r.overview && h("div", { class: "result-overview" }, r.overview),
|
||||
),
|
||||
action,
|
||||
);
|
||||
});
|
||||
if (full) nodes.unshift(h("p", { class: "alert alert--warn" }, icon("info"), `This list is full (${fmt.format(list.maxItems)}). Raise its size in List settings to add more.`));
|
||||
results.replaceChildren(...nodes);
|
||||
}
|
||||
|
||||
async function addResult(r, button) {
|
||||
// Theater entries need the owner to say which production they mean.
|
||||
if (cat.key === "theater") {
|
||||
openItemForm({ result: r });
|
||||
return;
|
||||
}
|
||||
busy(button, true);
|
||||
await createItem({ ...fromResult(r), details: true }, () => busy(button, false));
|
||||
}
|
||||
|
||||
function fromResult(r) {
|
||||
return {
|
||||
title: r.title, subtitle: r.subtitle, year: r.year, externalUrl: r.externalUrl,
|
||||
imageUrl: r.imageUrl, provider: r.provider, providerId: r.providerId, extra: { ...(r.extra || {}) },
|
||||
};
|
||||
}
|
||||
|
||||
async function createItem(body, done) {
|
||||
try {
|
||||
let res;
|
||||
try {
|
||||
res = await api("POST", `/api/lists/${list.id}/items`, body);
|
||||
} catch (err) {
|
||||
if (err.status !== 409) throw err;
|
||||
const again = await confirmDialog({ title: "Already ranked", message: `${err.message} Add it again anyway?`, confirm: "Add again" });
|
||||
if (!again) return null;
|
||||
res = await api("POST", `/api/lists/${list.id}/items`, { ...body, force: true });
|
||||
}
|
||||
list.itemCount++;
|
||||
renderHeader();
|
||||
toast(`Added “${res.item.title}” at #${res.item.rank}`);
|
||||
if (res.warning) toast(res.warning, { error: true });
|
||||
markResult(res.item, res.item.rank);
|
||||
await load(Math.ceil(res.item.rank / pageSize), res.item.id);
|
||||
return res.item;
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
return null;
|
||||
} finally {
|
||||
done?.();
|
||||
}
|
||||
}
|
||||
|
||||
const runSearch = debounce((q) => search(q), 450);
|
||||
searchInput.addEventListener("input", () => runSearch(searchInput.value));
|
||||
searchForm.addEventListener("submit", (e) => { e.preventDefault(); search(searchInput.value); });
|
||||
|
||||
document.querySelector("[data-action=manual]").addEventListener("click", () => openItemForm({}));
|
||||
|
||||
// ---------- item form (add manually / edit / theater add) ----------
|
||||
|
||||
function openItemForm({ item, result }) {
|
||||
const editing = !!item;
|
||||
const src = item || (result ? fromResult(result) : { extra: {} });
|
||||
const extra = { ...(src.extra || {}) };
|
||||
let clearImage = false;
|
||||
let dlg;
|
||||
|
||||
const field = (label, input, hint) => h("label", { class: "field" },
|
||||
h("span", { class: "field-label" }, label), input, hint && h("span", { class: "field-hint" }, hint));
|
||||
|
||||
const title = h("input", { required: true, maxlength: 500, value: src.title || "" });
|
||||
const subtitle = h("input", { maxlength: 500, value: src.subtitle || "" });
|
||||
const year = h("input", { maxlength: 20, value: src.year || "", inputmode: "numeric", style: { maxWidth: "140px" } });
|
||||
const note = h("textarea", { rows: 3, maxlength: 10000, value: item?.note || "", placeholder: "Why it's here. Shown to visitors." });
|
||||
const link = h("input", { type: "url", maxlength: 2000, value: src.externalUrl || "", placeholder: "https://" });
|
||||
|
||||
// Theater production gets top billing with suggestions.
|
||||
let production, productionList;
|
||||
if (cat.key === "theater") {
|
||||
productionList = h("datalist", { id: "productions" }, productions.map((p) => h("option", { value: p })));
|
||||
production = h("input", { list: "productions", maxlength: 200, value: extra.production || "", placeholder: "e.g. Broadway, North American Tour" });
|
||||
}
|
||||
const extraInputs = (EXTRA_FIELDS[cat.key] || []).map(([key, label]) => {
|
||||
const input = h("input", { maxlength: 500, value: extra[key] || "" });
|
||||
return { key, label, input };
|
||||
});
|
||||
|
||||
// Artwork
|
||||
const currentArt = item?.image ? `/images/${item.image}` : (src.imageUrl || "");
|
||||
const preview = h("div", {}, artBox(currentArt));
|
||||
const imageUrl = h("input", {
|
||||
type: "url", placeholder: "Paste an image URL",
|
||||
value: editing ? (item.imageSource && item.imageSource !== "upload" ? item.imageSource : "") : (src.imageUrl || ""),
|
||||
});
|
||||
imageUrl.addEventListener("change", () => {
|
||||
clearImage = false;
|
||||
preview.replaceChildren(artBox(imageUrl.value.trim()));
|
||||
});
|
||||
const fileInput = h("input", { type: "file", accept: "image/jpeg,image/png,image/webp,image/gif,image/avif", hidden: true });
|
||||
const uploadBtn = h("button", { type: "button", class: "btn btn--sm", onclick: () => fileInput.click() }, icon("upload"), "Upload");
|
||||
fileInput.addEventListener("change", async () => {
|
||||
const file = fileInput.files[0];
|
||||
if (!file) return;
|
||||
if (!editing) {
|
||||
toast("Save the entry first, then upload art for it.", { error: true });
|
||||
return;
|
||||
}
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
busy(uploadBtn, true);
|
||||
try {
|
||||
const res = await api("POST", `/api/items/${item.id}/image`, fd);
|
||||
Object.assign(item, res.item);
|
||||
imageUrl.value = "";
|
||||
clearImage = false;
|
||||
preview.replaceChildren(artBox(`/images/${res.item.image}`));
|
||||
toast("Artwork updated");
|
||||
await load(page);
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
} finally {
|
||||
busy(uploadBtn, false);
|
||||
fileInput.value = "";
|
||||
}
|
||||
});
|
||||
const removeArt = h("button", {
|
||||
type: "button", class: "btn btn--sm btn--ghost",
|
||||
onclick: () => { clearImage = true; imageUrl.value = ""; preview.replaceChildren(artBox("")); },
|
||||
}, icon("x"), "Remove");
|
||||
|
||||
const artHint = cat.key === "theater"
|
||||
? "Tip: use a poster from the specific production (a tour's key art, a revival's Playbill…)."
|
||||
: "Art is saved to your server, so it keeps working if the source changes.";
|
||||
|
||||
const error = h("p", { class: "alert alert--error", role: "alert", hidden: true });
|
||||
const save = h("button", { type: "submit", class: "btn btn--primary" }, editing ? "Save" : `Add at #${list.itemCount + 1}`);
|
||||
const heading = editing ? `Edit #${item.rank}` : result ? `Add “${result.title}”` : `Add a ${cat.singular.toLowerCase()}`;
|
||||
|
||||
const form = h("form", { novalidate: true },
|
||||
dialogHead(heading, () => dlg),
|
||||
h("div", { class: "dialog-body stack" },
|
||||
production && field("Production", production, "Which staging this is about. Pick one or type your own."),
|
||||
productionList,
|
||||
h("div", { class: "art-edit" + (square ? " is-square" : "") },
|
||||
preview,
|
||||
h("div", { class: "art-edit-actions" },
|
||||
h("span", { class: "field-label" }, "Artwork"),
|
||||
imageUrl,
|
||||
h("div", { class: "row-btns" }, editing && uploadBtn, removeArt, fileInput),
|
||||
h("span", { class: "field-hint" }, artHint),
|
||||
),
|
||||
),
|
||||
field("Title", title),
|
||||
h("div", { class: "row" },
|
||||
field(cat.subtitleHint, subtitle),
|
||||
field(cat.key === "theater" ? "Year (of this production)" : "Year", year),
|
||||
),
|
||||
extraInputs.length > 0 && h("div", { class: "row" }, extraInputs.map((x) => field(x.label, x.input))),
|
||||
field("Your note", note),
|
||||
field("Link", link, "Where the title links to on your page."),
|
||||
error,
|
||||
),
|
||||
h("div", { class: "dialog-foot" },
|
||||
h("button", { type: "button", class: "btn", onclick: () => dlg.close() }, "Cancel"),
|
||||
save,
|
||||
),
|
||||
);
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
error.hidden = true;
|
||||
if (!title.value.trim()) {
|
||||
error.hidden = false;
|
||||
error.textContent = "Give it a title.";
|
||||
title.focus();
|
||||
return;
|
||||
}
|
||||
const newExtra = { ...extra };
|
||||
if (production) newExtra.production = production.value.trim();
|
||||
for (const x of extraInputs) newExtra[x.key] = x.input.value.trim();
|
||||
const body = {
|
||||
title: title.value, subtitle: subtitle.value, year: year.value, note: note.value,
|
||||
externalUrl: link.value.trim(), extra: newExtra,
|
||||
imageUrl: clearImage ? "" : imageUrl.value.trim(), clearImage,
|
||||
};
|
||||
busy(save, true);
|
||||
try {
|
||||
if (editing) {
|
||||
await api("PUT", `/api/items/${item.id}`, body);
|
||||
dlg.close();
|
||||
toast("Saved");
|
||||
await load(page, item.id);
|
||||
} else {
|
||||
Object.assign(body, {
|
||||
provider: result?.provider || "", providerId: result?.providerId || "", details: !!result,
|
||||
});
|
||||
const created = await createItem(body);
|
||||
if (created) dlg.close();
|
||||
}
|
||||
} catch (err) {
|
||||
error.hidden = false;
|
||||
error.textContent = err.message;
|
||||
} finally {
|
||||
busy(save, false);
|
||||
}
|
||||
});
|
||||
|
||||
dlg = openDialog(form);
|
||||
(production || title).focus();
|
||||
}
|
||||
|
||||
renderHeader();
|
||||
load(1);
|
||||
@@ -0,0 +1,110 @@
|
||||
// Admin dashboard: all lists, their order, create/edit/delete.
|
||||
import { h, icon, api, readBoot, toast, confirmDialog, fmt } from "./common.js";
|
||||
import { sortable } from "./sortable.js";
|
||||
import { openListForm } from "./list-form.js";
|
||||
|
||||
const boot = readBoot();
|
||||
const { categories, limits } = boot;
|
||||
const covers = boot.covers || {};
|
||||
const catByKey = Object.fromEntries(categories.map((c) => [c.key, c]));
|
||||
let lists = boot.lists;
|
||||
|
||||
const root = document.getElementById("lists");
|
||||
|
||||
function newList(category) {
|
||||
openListForm({
|
||||
categories, limits, category,
|
||||
onSaved: (l) => { location.href = `/admin/lists/${l.id}`; },
|
||||
});
|
||||
}
|
||||
|
||||
function editList(list) {
|
||||
openListForm({
|
||||
categories, limits, list,
|
||||
onSaved: (saved) => {
|
||||
lists = lists.map((l) => (l.id === saved.id ? saved : l));
|
||||
render();
|
||||
toast("List saved");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteList(list) {
|
||||
const entries = list.itemCount ? ` Its ${fmt.format(list.itemCount)} ${list.itemCount === 1 ? "entry" : "entries"} will be removed.` : "";
|
||||
const ok = await confirmDialog({
|
||||
title: "Delete list?",
|
||||
message: `“${list.title}” will be deleted.${entries} This can't be undone.`,
|
||||
confirm: "Delete list",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
try {
|
||||
await api("DELETE", `/api/lists/${list.id}`);
|
||||
lists = lists.filter((l) => l.id !== list.id);
|
||||
render();
|
||||
toast("List deleted");
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
}
|
||||
}
|
||||
|
||||
function card(list) {
|
||||
const cat = catByKey[list.category];
|
||||
const pct = Math.min(100, Math.round((list.itemCount / list.maxItems) * 100));
|
||||
const imgs = covers[list.id] || [];
|
||||
const art = imgs.length
|
||||
? h("span", { class: "list-card-covers" + (cat.aspect === "square" ? " is-square" : "") },
|
||||
imgs.map((src) => h("span", { style: { backgroundImage: `url("${src}")` } })))
|
||||
: h("span", { class: "shelf-icon" }, icon(cat.icon));
|
||||
return h("li", { class: "list-card", "data-id": list.id },
|
||||
h("button", { type: "button", class: "drag-handle", "aria-label": `Reorder ${list.title}. Use arrow keys to move.` }, icon("grip")),
|
||||
h("a", { class: "list-card-main", href: `/admin/lists/${list.id}` },
|
||||
art,
|
||||
h("span", { style: { minWidth: 0 } },
|
||||
h("span", { class: "list-card-title" }, list.title),
|
||||
h("span", { class: "list-card-meta" },
|
||||
h("span", {}, cat.label),
|
||||
h("span", { "aria-hidden": "true" }, "·"),
|
||||
h("span", {}, `${fmt.format(list.itemCount)} / ${fmt.format(list.maxItems)}`),
|
||||
h("span", { class: "list-card-bar", "aria-hidden": "true" }, h("span", { style: { width: pct + "%" } })),
|
||||
!list.visible && h("span", { class: "badge badge--muted" }, icon("eye-off"), "Hidden"),
|
||||
),
|
||||
),
|
||||
),
|
||||
h("div", { class: "list-card-actions" },
|
||||
h("a", { class: "icon-btn", href: `/l/${list.slug}`, title: "View public page", "aria-label": "View public page" }, icon("external")),
|
||||
h("button", { type: "button", class: "icon-btn", title: "List settings", "aria-label": "List settings", onclick: () => editList(list) }, icon("settings")),
|
||||
h("button", { type: "button", class: "icon-btn icon-btn--danger", title: "Delete", "aria-label": "Delete list", onclick: () => deleteList(list) }, icon("trash")),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!lists.length) {
|
||||
root.replaceChildren(h("div", { class: "onboard" },
|
||||
h("div", { class: "empty-art", style: { margin: "0 auto 16px" } }, icon("deck")),
|
||||
h("h2", {}, "Start your first list"),
|
||||
h("p", {}, "Pick a category. You'll choose how many spots it has next."),
|
||||
h("div", { class: "quick-cats" },
|
||||
categories.map((c) => h("button", { type: "button", onclick: () => newList(c.key) }, icon(c.icon), c.label))),
|
||||
));
|
||||
return;
|
||||
}
|
||||
const ul = h("ul", { class: "admin-lists", style: { listStyle: "none", margin: 0, padding: 0 } }, lists.map(card));
|
||||
sortable(ul, {
|
||||
onMove: async () => {
|
||||
const ids = [...ul.children].map((li) => Number(li.dataset.id));
|
||||
lists = ids.map((id) => lists.find((l) => l.id === id));
|
||||
try {
|
||||
await api("POST", "/api/lists/order", { ids });
|
||||
toast("Order saved");
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
}
|
||||
},
|
||||
});
|
||||
root.replaceChildren(ul);
|
||||
}
|
||||
|
||||
document.querySelector("[data-action=new-list]").addEventListener("click", () => newList());
|
||||
render();
|
||||
@@ -0,0 +1,360 @@
|
||||
// Settings: profile, appearance, integrations, account.
|
||||
import { h, icon, api, toast, busy } from "./common.js";
|
||||
|
||||
const root = document.getElementById("settings");
|
||||
let settings;
|
||||
|
||||
const field = (label, input, hint) => h("label", { class: "field" },
|
||||
h("span", { class: "field-label" }, label), input, hint && h("span", { class: "field-hint" }, hint));
|
||||
|
||||
function section(id, title, desc, ...body) {
|
||||
return h("section", { class: "settings-section", id },
|
||||
h("h2", {}, title),
|
||||
desc && h("p", { class: "section-desc" }, desc),
|
||||
h("div", { class: "panel" }, ...body));
|
||||
}
|
||||
|
||||
async function saveSettings(patch, button, message = "Saved") {
|
||||
if (button) busy(button, true);
|
||||
try {
|
||||
settings = await api("PUT", "/api/settings", patch);
|
||||
toast(message);
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
return false;
|
||||
} finally {
|
||||
if (button) busy(button, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- profile ----------
|
||||
|
||||
function profileSection() {
|
||||
const avatarBox = h("div", { class: "avatar" });
|
||||
const renderAvatar = () => {
|
||||
avatarBox.replaceChildren(settings.avatar
|
||||
? h("img", { src: settings.avatar, alt: "" })
|
||||
: h("span", {}, (settings.ownerName || settings.siteTitle || "T").trim().charAt(0).toUpperCase()));
|
||||
removeBtn.hidden = !settings.avatar;
|
||||
};
|
||||
const file = h("input", { type: "file", accept: "image/jpeg,image/png,image/webp,image/gif,image/avif", hidden: true });
|
||||
const uploadBtn = h("button", { type: "button", class: "btn btn--sm", onclick: () => file.click() }, icon("upload"), "Upload picture");
|
||||
const removeBtn = h("button", {
|
||||
type: "button", class: "btn btn--sm btn--ghost",
|
||||
onclick: async () => {
|
||||
try {
|
||||
await api("DELETE", "/api/settings/avatar");
|
||||
settings.avatar = "";
|
||||
renderAvatar();
|
||||
toast("Picture removed");
|
||||
} catch (err) { toast(err.message, { error: true }); }
|
||||
},
|
||||
}, "Remove");
|
||||
file.addEventListener("change", async () => {
|
||||
if (!file.files[0]) return;
|
||||
const fd = new FormData();
|
||||
fd.append("file", file.files[0]);
|
||||
busy(uploadBtn, true);
|
||||
try {
|
||||
const res = await api("POST", "/api/settings/avatar", fd);
|
||||
settings.avatar = res.avatar;
|
||||
renderAvatar();
|
||||
toast("Picture updated");
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
} finally {
|
||||
busy(uploadBtn, false);
|
||||
file.value = "";
|
||||
}
|
||||
});
|
||||
|
||||
const ownerName = h("input", { maxlength: 100, value: settings.ownerName, placeholder: "Your name" });
|
||||
const siteTitle = h("input", { maxlength: 100, value: settings.siteTitle, placeholder: "TopDeck" });
|
||||
const tagline = h("input", { maxlength: 300, value: settings.tagline, placeholder: "A line about you or your taste" });
|
||||
const preview = h("input", { type: "number", min: 0, max: 50, value: settings.previewCount, style: { maxWidth: "120px" } });
|
||||
const notes = h("input", { type: "checkbox", checked: settings.showNotes });
|
||||
const save = h("button", { type: "submit", class: "btn btn--primary" }, "Save profile");
|
||||
|
||||
const form = h("form", { class: "stack" },
|
||||
h("div", { class: "avatar-edit" }, avatarBox, h("div", { class: "row-btns", style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, uploadBtn, removeBtn, file)),
|
||||
h("div", { class: "row" }, field("Your name", ownerName, "Shown as the page heading."), field("Site title", siteTitle, "Shown in the header and browser tab.")),
|
||||
field("Tagline", tagline),
|
||||
field("Entries per list on the home page", preview, "Visitors see the full list on each list's page. 0 shows only the heading."),
|
||||
h("label", { class: "check" }, notes, "Show my notes to visitors"),
|
||||
h("div", { class: "settings-actions" }, save),
|
||||
);
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const ok = await saveSettings({
|
||||
ownerName: ownerName.value, siteTitle: siteTitle.value, tagline: tagline.value,
|
||||
previewCount: Number(preview.value), showNotes: notes.checked,
|
||||
}, save, "Profile saved");
|
||||
if (ok) {
|
||||
renderAvatar();
|
||||
const brand = document.querySelector(".brand-name");
|
||||
if (brand) brand.textContent = settings.siteTitle || "TopDeck";
|
||||
}
|
||||
});
|
||||
renderAvatar();
|
||||
return section("profile", "Profile", "Who's behind the lists.", form);
|
||||
}
|
||||
|
||||
// ---------- appearance ----------
|
||||
|
||||
const CSS_EXAMPLE = `/* Override any theme variable. */
|
||||
:root, [data-theme] {
|
||||
--accent: #ff5a7a;
|
||||
--radius-art: 14px;
|
||||
}
|
||||
|
||||
/* Or restyle anything, e.g. bigger posters: */
|
||||
.items--grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
|
||||
`;
|
||||
|
||||
function appearanceSection() {
|
||||
const html = document.documentElement;
|
||||
const cards = h("div", { class: "themes", role: "radiogroup", "aria-label": "Theme" },
|
||||
settings.themes.map((t) => h("label", { class: "theme-card" },
|
||||
h("input", {
|
||||
type: "radio", name: "theme", value: t.key, checked: t.key === settings.theme,
|
||||
onchange: async () => {
|
||||
html.dataset.theme = t.key;
|
||||
await saveSettings({ theme: t.key }, null, `Theme set to ${t.label}`);
|
||||
},
|
||||
}),
|
||||
h("span", { class: "theme-swatch", "data-theme": t.key },
|
||||
h("span", { class: "theme-preview" }, h("i"), h("i"), h("i"), h("i")),
|
||||
h("span", { class: "theme-name" }, t.label, h("small", { class: "theme-kind" }, t.dark ? "Dark" : "Light")),
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
const css = h("textarea", { class: "code", spellcheck: false, value: settings.customCss, placeholder: CSS_EXAMPLE, "aria-label": "Custom CSS" });
|
||||
css.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Tab" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
css.setRangeText(" ", css.selectionStart, css.selectionEnd, "end");
|
||||
}
|
||||
});
|
||||
let live = document.querySelector("link[href^='/custom.css']");
|
||||
const previewStyle = h("style");
|
||||
const previewBtn = h("button", {
|
||||
type: "button", class: "btn",
|
||||
onclick: () => {
|
||||
live?.remove();
|
||||
live = null;
|
||||
previewStyle.textContent = css.value;
|
||||
document.head.append(previewStyle);
|
||||
toast("Previewing on this page. Save to publish.");
|
||||
},
|
||||
}, icon("eye"), "Preview");
|
||||
const exampleBtn = h("button", { type: "button", class: "btn btn--ghost", onclick: () => { css.value = CSS_EXAMPLE; css.focus(); } }, "Insert example");
|
||||
const save = h("button", { type: "button", class: "btn btn--primary" }, "Save CSS");
|
||||
save.addEventListener("click", async () => {
|
||||
if (await saveSettings({ customCss: css.value }, save, "Custom CSS saved")) {
|
||||
live?.remove();
|
||||
live = null;
|
||||
previewStyle.textContent = css.value;
|
||||
document.head.append(previewStyle);
|
||||
}
|
||||
});
|
||||
|
||||
return section("appearance", "Appearance", "Pick a preset, then fine-tune it with your own CSS if you like.",
|
||||
h("div", { class: "field" }, h("span", { class: "field-label" }, "Theme"), cards),
|
||||
h("div", { class: "field" },
|
||||
h("span", { class: "field-label" }, "Custom CSS"),
|
||||
css,
|
||||
h("span", { class: "field-hint" }, "Loaded after the theme on every page. Every color is a CSS variable (see themes.css), so a few lines can make a whole new theme."),
|
||||
),
|
||||
h("div", { class: "settings-actions" }, exampleBtn, previewBtn, save),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- integrations ----------
|
||||
|
||||
function secretInput(key, label, hintHTML) {
|
||||
const st = settings.secrets[key];
|
||||
const input = h("input", {
|
||||
type: "password", autocomplete: "off", spellcheck: false,
|
||||
placeholder: st.set ? `Saved (${st.hint}). Type to replace.` : "Not set",
|
||||
disabled: st.locked,
|
||||
});
|
||||
const hint = h("span", { class: "field-hint" });
|
||||
if (st.locked) hint.textContent = `Set by the ${"TOPDECK_" + key.toUpperCase()} environment variable.`;
|
||||
else if (hintHTML) hint.append(...hintHTML);
|
||||
const wrap = field(label, input);
|
||||
wrap.append(hint);
|
||||
return { key, input, wrap, st };
|
||||
}
|
||||
|
||||
function testButton(category, out) {
|
||||
const btn = h("button", { type: "button", class: "btn btn--sm" }, icon("refresh"), "Test");
|
||||
btn.addEventListener("click", async () => {
|
||||
busy(btn, true);
|
||||
out.textContent = "Testing…";
|
||||
out.className = "test-result";
|
||||
try {
|
||||
const res = await api("POST", "/api/integrations/test", { category });
|
||||
out.textContent = res.message;
|
||||
out.className = "test-result " + (res.ok ? "is-ok" : "is-error");
|
||||
} catch (err) {
|
||||
out.textContent = err.message;
|
||||
out.className = "test-result is-error";
|
||||
} finally {
|
||||
busy(btn, false);
|
||||
}
|
||||
});
|
||||
return btn;
|
||||
}
|
||||
|
||||
const extLink = (href, text) => h("a", { href, target: "_blank", rel: "noopener noreferrer" }, text);
|
||||
|
||||
function integration({ title, iconName, desc, category, secrets = [], extra = [], ready }) {
|
||||
const out = h("span", { class: "test-result", "aria-live": "polite" });
|
||||
const status = h("span", { class: "status" });
|
||||
const setStatus = () => {
|
||||
const ok = ready();
|
||||
status.textContent = ok ? "Ready" : "Needs a key";
|
||||
status.className = "status " + (ok ? "is-ok" : "is-off");
|
||||
};
|
||||
const editable = secrets.filter((s) => !s.st.locked);
|
||||
const save = editable.length > 0 && h("button", { type: "button", class: "btn btn--sm btn--primary" }, "Save");
|
||||
const clear = editable.some((s) => s.st.set) && h("button", { type: "button", class: "btn btn--sm btn--ghost" }, "Clear");
|
||||
const collect = (clearAll) => {
|
||||
const patch = {};
|
||||
for (const s of editable) {
|
||||
if (clearAll) patch[s.key] = "";
|
||||
else if (s.input.value.trim()) patch[s.key] = s.input.value.trim();
|
||||
}
|
||||
return patch;
|
||||
};
|
||||
const refresh = () => {
|
||||
for (const s of secrets) {
|
||||
s.st = settings.secrets[s.key];
|
||||
s.input.value = "";
|
||||
s.input.placeholder = s.st.set ? `Saved (${s.st.hint}). Type to replace.` : "Not set";
|
||||
}
|
||||
setStatus();
|
||||
};
|
||||
save && save.addEventListener("click", async () => {
|
||||
const patch = collect(false);
|
||||
if (!Object.keys(patch).length) { toast("Type a key first", { error: true }); return; }
|
||||
if (await saveSettings(patch, save, `${title} saved`)) refresh();
|
||||
});
|
||||
clear && clear.addEventListener("click", async () => {
|
||||
if (await saveSettings(collect(true), clear, `${title} keys cleared`)) refresh();
|
||||
});
|
||||
setStatus();
|
||||
return h("div", { class: "integration" },
|
||||
h("div", { class: "integration-head" },
|
||||
h("div", {}, h("h3", {}, icon(iconName), title), h("p", {}, desc)),
|
||||
status,
|
||||
),
|
||||
...extra,
|
||||
...secrets.map((s) => s.wrap),
|
||||
h("div", { style: { display: "flex", gap: "8px", alignItems: "center", flexWrap: "wrap" } },
|
||||
testButton(category, out), save, clear, out),
|
||||
);
|
||||
}
|
||||
|
||||
function providerChoice(settingKey, options) {
|
||||
const name = "choice-" + settingKey;
|
||||
return h("div", { class: "radio-cards", role: "radiogroup" },
|
||||
options.map(([value, label]) => h("label", {},
|
||||
h("input", {
|
||||
type: "radio", name, value, checked: settings[settingKey] === value,
|
||||
onchange: () => saveSettings({ [settingKey]: value }, null, `Now using ${label.split(" (")[0]}`),
|
||||
}),
|
||||
label)));
|
||||
}
|
||||
|
||||
function integrationsSection() {
|
||||
const tmdb = secretInput("tmdb_api_key", "API key or Read Access Token", [
|
||||
"Free with a TMDB account: ", extLink("https://www.themoviedb.org/settings/api", "themoviedb.org/settings/api"), ". Either the v3 key or the v4 token works."]);
|
||||
const tvdb = secretInput("tvdb_api_key", "API key", [
|
||||
"Get one at ", extLink("https://thetvdb.com/api-information", "thetvdb.com/api-information"), "."]);
|
||||
const tvdbPin = secretInput("tvdb_pin", "Subscriber PIN (optional)", ["Only needed for user-supported keys."]);
|
||||
const igdbId = secretInput("igdb_client_id", "Twitch Client ID", [
|
||||
"IGDB uses Twitch logins. Register an app at ", extLink("https://dev.twitch.tv/console/apps", "dev.twitch.tv/console"), " (see ",
|
||||
extLink("https://api-docs.igdb.com/#account-creation", "IGDB's guide"), ")."]);
|
||||
const igdbSecret = secretInput("igdb_client_secret", "Twitch Client Secret");
|
||||
|
||||
const has = (k) => settings.secrets[k].set;
|
||||
return section("integrations", "Integrations", "Where search results and artwork come from. Keys are stored on your server and never shown on your public page.",
|
||||
integration({
|
||||
title: "Movies · TMDB", iconName: "film", category: "movie",
|
||||
desc: "The Movie Database: posters, directors, genres.",
|
||||
secrets: [tmdb], ready: () => has("tmdb_api_key"),
|
||||
}),
|
||||
integration({
|
||||
title: "TV Shows", iconName: "tv", category: "tv",
|
||||
desc: "TheTVDB by default. TMDB also works if you'd rather use one key for both.",
|
||||
extra: [providerChoice("tvProvider", [["tvdb", "TheTVDB"], ["tmdb", "TMDB (uses the key above)"]])],
|
||||
secrets: [tvdb, tvdbPin],
|
||||
ready: () => settings.tvProvider === "tmdb" ? has("tmdb_api_key") : has("tvdb_api_key"),
|
||||
}),
|
||||
integration({
|
||||
title: "Video Games · IGDB", iconName: "gamepad", category: "game",
|
||||
desc: "The Internet Game Database: covers, developers, platforms.",
|
||||
secrets: [igdbId, igdbSecret], ready: () => has("igdb_client_id") && has("igdb_client_secret"),
|
||||
}),
|
||||
integration({
|
||||
title: "Music · Songs & Albums", iconName: "disc", category: "album",
|
||||
desc: "No key needed. Deezer has the best cover art and fast search; MusicBrainz is fully open data but slower (1 request/second).",
|
||||
extra: [providerChoice("musicProvider", [["deezer", "Deezer (recommended)"], ["musicbrainz", "MusicBrainz + Cover Art Archive"]])],
|
||||
ready: () => true,
|
||||
}),
|
||||
integration({
|
||||
title: "Theater · Wikipedia", iconName: "masks", category: "theater",
|
||||
desc: "No key needed. Finds musicals, plays and operas on Wikipedia. You choose the production (Broadway, a tour…) and can swap in its own poster.",
|
||||
ready: () => true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- account ----------
|
||||
|
||||
function accountSection() {
|
||||
const username = h("input", { autocomplete: "username", maxlength: 64, value: settings.username, required: true });
|
||||
const current = h("input", { type: "password", autocomplete: "current-password", required: true });
|
||||
const next = h("input", { type: "password", autocomplete: "new-password", minlength: 8, placeholder: "Leave blank to keep" });
|
||||
const confirm = h("input", { type: "password", autocomplete: "new-password" });
|
||||
const save = h("button", { type: "submit", class: "btn btn--primary" }, "Update account");
|
||||
const form = h("form", { class: "stack" },
|
||||
field("Username", username),
|
||||
h("div", { class: "row" }, field("New password", next), field("Confirm new password", confirm)),
|
||||
field("Current password", current, "Required to make changes. Changing your password signs out other browsers."),
|
||||
h("div", { class: "settings-actions" }, save),
|
||||
);
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
if (next.value && next.value !== confirm.value) { toast("The new passwords don't match", { error: true }); return; }
|
||||
if (next.value && next.value.length < 8) { toast("Use at least 8 characters", { error: true }); return; }
|
||||
busy(save, true);
|
||||
try {
|
||||
const res = await api("PUT", "/api/account", { username: username.value, currentPassword: current.value, newPassword: next.value });
|
||||
settings.username = res.username;
|
||||
current.value = next.value = confirm.value = "";
|
||||
toast("Account updated");
|
||||
} catch (err) {
|
||||
toast(err.message, { error: true });
|
||||
} finally {
|
||||
busy(save, false);
|
||||
}
|
||||
});
|
||||
return section("account", "Account", "", form);
|
||||
}
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
settings = await api("GET", "/api/settings");
|
||||
} catch (err) {
|
||||
root.replaceChildren(h("p", { class: "alert alert--error" }, icon("alert"), err.message));
|
||||
return;
|
||||
}
|
||||
root.replaceChildren(profileSection(), appearanceSection(), integrationsSection(), accountSection());
|
||||
root.removeAttribute("aria-busy");
|
||||
if (location.hash) document.querySelector(location.hash)?.scrollIntoView();
|
||||
}
|
||||
init();
|
||||
@@ -0,0 +1,160 @@
|
||||
// Shared helpers for TopDeck's pages. No build step, no dependencies.
|
||||
|
||||
/** Create an element: h("button", { class: "btn", onclick }, "Save") */
|
||||
export function h(tag, attrs = {}, ...children) {
|
||||
const el = document.createElement(tag);
|
||||
let value;
|
||||
for (const [k, v] of Object.entries(attrs || {})) {
|
||||
if (v === false || v == null) continue;
|
||||
if (k === "value") value = v;
|
||||
else if (k.startsWith("on") && typeof v === "function") el.addEventListener(k.slice(2), v);
|
||||
else if (k === "class") el.className = v;
|
||||
else if (k === "style" && typeof v === "object") Object.assign(el.style, v);
|
||||
else if (k in el && typeof v !== "string") el[k] = v;
|
||||
else el.setAttribute(k, v === true ? "" : v);
|
||||
}
|
||||
append(el, children);
|
||||
// Set after children so <select> options exist.
|
||||
if (value !== undefined) el.value = value;
|
||||
return el;
|
||||
}
|
||||
|
||||
function append(el, children) {
|
||||
for (const c of children.flat(Infinity)) {
|
||||
if (c == null || c === false) continue;
|
||||
el.append(c instanceof Node ? c : document.createTextNode(String(c)));
|
||||
}
|
||||
}
|
||||
|
||||
const SVG = "http://www.w3.org/2000/svg";
|
||||
|
||||
export function icon(name) {
|
||||
const svg = document.createElementNS(SVG, "svg");
|
||||
svg.setAttribute("class", "icon");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
const use = document.createElementNS(SVG, "use");
|
||||
use.setAttribute("href", `/static/img/icons.svg#${name}`);
|
||||
svg.append(use);
|
||||
return svg;
|
||||
}
|
||||
|
||||
export function readBoot() {
|
||||
const el = document.getElementById("boot");
|
||||
return el ? JSON.parse(el.textContent) : {};
|
||||
}
|
||||
|
||||
export class APIError extends Error {
|
||||
constructor(message, status, body) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
|
||||
/** Call the admin JSON API. Throws APIError with a human message. */
|
||||
export async function api(method, path, body) {
|
||||
const opts = { method, headers: { "X-TopDeck": "1" }, credentials: "same-origin" };
|
||||
if (body instanceof FormData) {
|
||||
opts.body = body;
|
||||
} else if (body !== undefined) {
|
||||
opts.headers["Content-Type"] = "application/json";
|
||||
opts.body = JSON.stringify(body);
|
||||
}
|
||||
let res;
|
||||
try {
|
||||
res = await fetch(path, opts);
|
||||
} catch {
|
||||
throw new APIError("Can't reach the server. Check your connection.", 0);
|
||||
}
|
||||
if (res.status === 204) return null;
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (res.status === 401) {
|
||||
location.href = "/login?next=" + encodeURIComponent(location.pathname);
|
||||
}
|
||||
if (!res.ok) throw new APIError(data.error || `Request failed (${res.status})`, res.status, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
let toastBox;
|
||||
export function toast(message, { error = false, timeout = 3200 } = {}) {
|
||||
if (!toastBox) {
|
||||
toastBox = h("div", { class: "toasts", role: "status", "aria-live": "polite" });
|
||||
document.body.append(toastBox);
|
||||
}
|
||||
const t = h("div", { class: "toast" + (error ? " toast--error" : "") }, icon(error ? "alert" : "check"), message);
|
||||
toastBox.append(t);
|
||||
setTimeout(() => {
|
||||
t.classList.add("is-leaving");
|
||||
setTimeout(() => t.remove(), 250);
|
||||
}, error ? Math.max(timeout, 5000) : timeout);
|
||||
}
|
||||
|
||||
/** Open a modal dialog. Returns the <dialog>; it removes itself on close. */
|
||||
export function openDialog(content, { className = "", onClose } = {}) {
|
||||
const dlg = h("dialog", { class: className }, content);
|
||||
dlg.addEventListener("click", (e) => {
|
||||
// Clicking the backdrop (outside the box) closes.
|
||||
if (e.target !== dlg) return;
|
||||
const r = dlg.getBoundingClientRect();
|
||||
const inside = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;
|
||||
if (!inside) dlg.close();
|
||||
});
|
||||
dlg.addEventListener("close", () => {
|
||||
onClose?.();
|
||||
dlg.remove();
|
||||
});
|
||||
document.body.append(dlg);
|
||||
dlg.showModal();
|
||||
return dlg;
|
||||
}
|
||||
|
||||
export function dialogHead(title, dlg) {
|
||||
return h("div", { class: "dialog-head" },
|
||||
h("h2", {}, title),
|
||||
h("button", { type: "button", class: "icon-btn", "aria-label": "Close", onclick: () => dlg().close() }, icon("x")),
|
||||
);
|
||||
}
|
||||
|
||||
/** Ask a yes/no question. Resolves true when confirmed. */
|
||||
export function confirmDialog({ title, message, confirm = "Confirm", danger = false }) {
|
||||
return new Promise((resolve) => {
|
||||
let ok = false;
|
||||
let dlg;
|
||||
const content = h("form", { method: "dialog" },
|
||||
dialogHead(title, () => dlg),
|
||||
h("div", { class: "dialog-body" }, h("p", { class: "muted" }, message)),
|
||||
h("div", { class: "dialog-foot" },
|
||||
h("button", { type: "button", class: "btn", onclick: () => dlg.close() }, "Cancel"),
|
||||
h("button", {
|
||||
type: "submit",
|
||||
class: "btn " + (danger ? "btn--danger btn--solid" : "btn--primary"),
|
||||
onclick: () => { ok = true; },
|
||||
}, confirm),
|
||||
),
|
||||
);
|
||||
dlg = openDialog(content, { onClose: () => resolve(ok) });
|
||||
dlg.style.maxWidth = "440px";
|
||||
});
|
||||
}
|
||||
|
||||
export function debounce(fn, ms) {
|
||||
let t;
|
||||
return (...args) => {
|
||||
clearTimeout(t);
|
||||
t = setTimeout(() => fn(...args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
export function busy(button, on) {
|
||||
button.disabled = on;
|
||||
button.setAttribute("aria-busy", on ? "true" : "false");
|
||||
}
|
||||
|
||||
export const fmt = new Intl.NumberFormat();
|
||||
|
||||
export function storageGet(key) {
|
||||
try { return localStorage.getItem(key); } catch { return null; }
|
||||
}
|
||||
export function storageSet(key, val) {
|
||||
try { localStorage.setItem(key, val); } catch { /* private mode */ }
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// Create / edit list dialog, shared by the dashboard and the list editor.
|
||||
import { h, icon, api, openDialog, dialogHead, busy, fmt } from "./common.js";
|
||||
|
||||
const SIZE_PRESETS = [5, 10, 25, 50, 100];
|
||||
|
||||
function sizeHint(n, limits) {
|
||||
if (!Number.isInteger(n) || n < 1) return { text: "Pick a size of at least 1.", cls: "is-error" };
|
||||
if (n > limits.max) return { text: `The most a list can hold is ${fmt.format(limits.max)}.`, cls: "is-error" };
|
||||
if (n > limits.warn) return { text: `That's a lot. Lists this long work, but they're hard to browse and rank. ${limits.recommended} or fewer is recommended.`, cls: "is-warn" };
|
||||
if (n > limits.recommended) return { text: `Heads up: ${limits.recommended} or fewer is recommended so visitors can take it all in.`, cls: "is-warn" };
|
||||
return { text: `Up to ${fmt.format(limits.max)} allowed; ${limits.recommended} or fewer recommended.`, cls: "" };
|
||||
}
|
||||
|
||||
const autoTitle = (n, cat) => `Top ${n} ${cat.label}`;
|
||||
|
||||
/**
|
||||
* @param {object} o
|
||||
* @param {object[]} o.categories
|
||||
* @param {object} o.limits
|
||||
* @param {object} [o.list] existing list to edit
|
||||
* @param {string} [o.category] preselected category for a new list
|
||||
* @param {(list: object) => void} o.onSaved
|
||||
*/
|
||||
export function openListForm({ categories, limits, list, category, onSaved }) {
|
||||
const editing = !!list;
|
||||
const catByKey = Object.fromEntries(categories.map((c) => [c.key, c]));
|
||||
const state = {
|
||||
category: list?.category || category || categories[0].key,
|
||||
size: list?.maxItems || 10,
|
||||
};
|
||||
// Keep the title in sync with size/category until the owner types their own.
|
||||
let titleTouched = editing && list.title !== autoTitle(list.maxItems, catByKey[list.category]);
|
||||
|
||||
const title = h("input", { name: "title", required: true, maxlength: 200, value: list?.title || autoTitle(state.size, catByKey[state.category]) });
|
||||
title.addEventListener("input", () => { titleTouched = true; });
|
||||
const syncTitle = () => { if (!titleTouched) title.value = autoTitle(state.size, catByKey[state.category]); };
|
||||
|
||||
const lockedCat = editing && list.itemCount > 0;
|
||||
const catPicker = h("div", { class: "cat-picker", role: "radiogroup", "aria-label": "Category" },
|
||||
categories.map((c) => h("label", { class: "cat-option" },
|
||||
h("input", {
|
||||
type: "radio", name: "category", value: c.key, checked: c.key === state.category,
|
||||
disabled: lockedCat && c.key !== state.category,
|
||||
onchange: () => { state.category = c.key; syncTitle(); },
|
||||
}),
|
||||
h("span", {}, icon(c.icon), c.label),
|
||||
)),
|
||||
);
|
||||
|
||||
const sizeInput = h("input", { type: "number", min: 1, max: limits.max, step: 1, value: state.size, inputmode: "numeric", style: { maxWidth: "140px" } });
|
||||
const hint = h("span", { class: "field-hint" });
|
||||
const chips = h("div", { class: "size-chips" });
|
||||
const renderSize = () => {
|
||||
const { text, cls } = sizeHint(state.size, limits);
|
||||
hint.textContent = text;
|
||||
hint.className = "field-hint " + cls;
|
||||
chips.replaceChildren(...SIZE_PRESETS.map((n) => h("button", {
|
||||
type: "button", "aria-pressed": String(n === state.size),
|
||||
onclick: () => { state.size = n; sizeInput.value = n; renderSize(); syncTitle(); },
|
||||
}, `Top ${n}`)));
|
||||
};
|
||||
sizeInput.addEventListener("input", () => { state.size = Number(sizeInput.value); renderSize(); syncTitle(); });
|
||||
renderSize();
|
||||
|
||||
const desc = h("textarea", { name: "description", rows: 2, maxlength: 1000, placeholder: "Optional: a line about what makes this list", value: list?.description || "" });
|
||||
const slug = editing && h("input", { name: "slug", value: list.slug, maxlength: 60, pattern: "[a-z0-9-]+", spellcheck: false });
|
||||
const layout = list?.layout || "grid";
|
||||
const layoutGroup = h("div", { class: "radio-cards" },
|
||||
h("label", {}, h("input", { type: "radio", name: "layout", value: "grid", checked: layout === "grid" }), icon("grid"), "Artwork grid"),
|
||||
h("label", {}, h("input", { type: "radio", name: "layout", value: "rows", checked: layout === "rows" }), icon("rows"), "Ranked list"),
|
||||
);
|
||||
const visible = h("input", { type: "checkbox", name: "visible", checked: list ? list.visible : true });
|
||||
const error = h("p", { class: "alert alert--error", role: "alert", hidden: true });
|
||||
const save = h("button", { type: "submit", class: "btn btn--primary" }, editing ? "Save changes" : "Create list");
|
||||
|
||||
let dlg;
|
||||
const form = h("form", { novalidate: true },
|
||||
dialogHead(editing ? "List settings" : "New list", () => dlg),
|
||||
h("div", { class: "dialog-body stack" },
|
||||
h("div", { class: "field" }, h("span", { class: "field-label" }, "Category"), catPicker,
|
||||
lockedCat && h("span", { class: "field-hint" }, "The category can't change once a list has entries.")),
|
||||
h("div", { class: "field" }, h("span", { class: "field-label" }, "How many?"),
|
||||
h("div", { class: "input-group", style: { alignItems: "center", flexWrap: "wrap" } }, chips, sizeInput), hint),
|
||||
h("label", { class: "field" }, h("span", { class: "field-label" }, "Title"), title),
|
||||
h("label", { class: "field" }, h("span", { class: "field-label" }, "Description"), desc),
|
||||
editing && h("label", { class: "field" }, h("span", { class: "field-label" }, "Address"),
|
||||
h("div", { class: "input-group", style: { alignItems: "center" } }, h("span", { class: "muted" }, "/l/"), slug)),
|
||||
h("div", { class: "field" }, h("span", { class: "field-label" }, "Layout"), layoutGroup),
|
||||
h("label", { class: "check" }, visible, "Show this list on my public page"),
|
||||
error,
|
||||
),
|
||||
h("div", { class: "dialog-foot" },
|
||||
h("button", { type: "button", class: "btn", onclick: () => dlg.close() }, "Cancel"),
|
||||
save,
|
||||
),
|
||||
);
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
error.hidden = true;
|
||||
const n = Number(sizeInput.value);
|
||||
if (!Number.isInteger(n) || n < 1 || n > limits.max) {
|
||||
error.hidden = false;
|
||||
error.textContent = sizeHint(n, limits).text;
|
||||
return;
|
||||
}
|
||||
const body = {
|
||||
title: title.value,
|
||||
category: state.category,
|
||||
maxItems: n,
|
||||
description: desc.value,
|
||||
layout: form.querySelector("input[name=layout]:checked").value,
|
||||
visible: visible.checked,
|
||||
};
|
||||
if (editing) body.slug = slug.value;
|
||||
busy(save, true);
|
||||
try {
|
||||
const saved = editing
|
||||
? await api("PUT", `/api/lists/${list.id}`, body)
|
||||
: await api("POST", "/api/lists", body);
|
||||
dlg.close();
|
||||
onSaved(saved);
|
||||
} catch (err) {
|
||||
error.hidden = false;
|
||||
error.textContent = err.message;
|
||||
} finally {
|
||||
busy(save, false);
|
||||
}
|
||||
});
|
||||
|
||||
dlg = openDialog(form);
|
||||
(editing ? title : catPicker.querySelector("input:checked"))?.focus();
|
||||
return dlg;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// Public pages: item detail dialog and grid/list toggle.
|
||||
import { h, icon, openDialog, storageGet, storageSet } from "./common.js";
|
||||
|
||||
// Each ranked list on the page ships its items as JSON next to the markup.
|
||||
const lists = [...document.querySelectorAll("[data-items]")].map((ol) => {
|
||||
const data = JSON.parse(ol.nextElementSibling?.textContent || "[]");
|
||||
return { ol, items: data, title: ol.dataset.listTitle, square: ol.classList.contains("aspect-square") };
|
||||
});
|
||||
|
||||
function findItem(id) {
|
||||
for (const list of lists) {
|
||||
const idx = list.items.findIndex((it) => it.id === id);
|
||||
if (idx >= 0) return { list, idx };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
let current = null;
|
||||
|
||||
function renderDialog(list, idx) {
|
||||
const it = list.items[idx];
|
||||
const art = it.image
|
||||
? h("img", { src: it.image, alt: `Artwork for ${it.title}` })
|
||||
: h("span", { class: "art-fallback" }, icon("image"));
|
||||
const sub = [it.subtitle, it.year].filter(Boolean).join(" · ");
|
||||
const topClass = it.rank <= 3 ? ` top${it.rank}` : "";
|
||||
const meta = it.meta.filter((m) => m.label !== "Production");
|
||||
|
||||
const prev = h("button", { type: "button", class: "icon-btn", "aria-label": "Previous", disabled: idx === 0, onclick: () => show(list, idx - 1) }, icon("chevron-left"));
|
||||
const next = h("button", { type: "button", class: "icon-btn", "aria-label": "Next", disabled: idx === list.items.length - 1, onclick: () => show(list, idx + 1) }, icon("chevron-right"));
|
||||
|
||||
return h("div", { class: "item-dialog-inner" },
|
||||
h("div", { class: "dlg-art" }, art),
|
||||
h("div", { class: "dlg-body" },
|
||||
h("button", { type: "button", class: "icon-btn dlg-close", "aria-label": "Close", onclick: () => current?.close() }, icon("x")),
|
||||
h("p", { class: "dlg-rank" + topClass }, h("strong", {}, `#${it.rank}`), h("span", {}, list.title)),
|
||||
h("h2", { class: "dlg-title" }, it.title),
|
||||
sub && h("p", { class: "dlg-sub" }, sub),
|
||||
it.badge && h("span", { class: "badge" }, it.badge),
|
||||
meta.length > 0 && h("dl", { class: "dlg-meta" }, meta.map((m) => [h("dt", {}, m.label), h("dd", {}, m.value)])),
|
||||
it.note && h("blockquote", { class: "dlg-note" }, it.note),
|
||||
h("div", { class: "dlg-actions" },
|
||||
it.link && h("a", { class: "btn btn--sm", href: it.link, target: "_blank", rel: "noopener noreferrer" },
|
||||
icon("external"), it.source ? `View on ${it.source}` : "Learn more"),
|
||||
h("div", { class: "dlg-nav" }, prev, next),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function show(list, idx) {
|
||||
const content = renderDialog(list, idx);
|
||||
if (current) {
|
||||
current.replaceChildren(content);
|
||||
} else {
|
||||
current = openDialog(content, {
|
||||
className: "item-dialog" + (list.square ? " is-square" : ""),
|
||||
onClose: () => { current = null; },
|
||||
});
|
||||
current.addEventListener("keydown", (e) => {
|
||||
if (e.key === "ArrowLeft") current.querySelector(".dlg-nav button:first-child")?.click();
|
||||
if (e.key === "ArrowRight") current.querySelector(".dlg-nav button:last-child")?.click();
|
||||
});
|
||||
}
|
||||
current.setAttribute("aria-label", `#${list.items[idx].rank} ${list.items[idx].title}`);
|
||||
}
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
const btn = e.target.closest("[data-item]");
|
||||
if (!btn) return;
|
||||
const found = findItem(Number(btn.dataset.item));
|
||||
if (found) show(found.list, found.idx);
|
||||
});
|
||||
|
||||
// Grid / list toggle on list pages, remembered per list in this browser.
|
||||
const toggle = document.querySelector("[data-layout-toggle]");
|
||||
if (toggle) {
|
||||
const key = "topdeck:layout:" + toggle.dataset.key;
|
||||
const apply = (layout) => {
|
||||
for (const { ol } of lists) {
|
||||
ol.classList.toggle("items--grid", layout === "grid");
|
||||
ol.classList.toggle("items--rows", layout === "rows");
|
||||
}
|
||||
for (const b of toggle.querySelectorAll("button")) b.setAttribute("aria-pressed", String(b.dataset.layout === layout));
|
||||
};
|
||||
apply(storageGet(key) || toggle.dataset.default);
|
||||
toggle.addEventListener("click", (e) => {
|
||||
const b = e.target.closest("button[data-layout]");
|
||||
if (!b) return;
|
||||
apply(b.dataset.layout);
|
||||
storageSet(key, b.dataset.layout);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
// Minimal drag-to-reorder for vertical lists. Works with mouse, touch and pen
|
||||
// via pointer events; the handle also supports ArrowUp/ArrowDown.
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} container element whose children are sortable
|
||||
* @param {object} opts
|
||||
* @param {string} opts.handle selector for the drag handle inside a child
|
||||
* @param {string} opts.placeholderClass classes for the gap left while dragging
|
||||
* @param {(el: HTMLElement, from: number, to: number) => void} opts.onMove
|
||||
*/
|
||||
export function sortable(container, { handle = ".drag-handle", placeholderClass = "is-placeholder", onMove }) {
|
||||
const children = () => [...container.children];
|
||||
|
||||
container.addEventListener("pointerdown", (e) => {
|
||||
const hdl = e.target.closest(handle);
|
||||
if (!hdl || !container.contains(hdl) || (e.pointerType === "mouse" && e.button !== 0)) return;
|
||||
const el = [...container.children].find((c) => c.contains(hdl));
|
||||
if (!el) return;
|
||||
e.preventDefault();
|
||||
|
||||
const from = children().indexOf(el);
|
||||
const rect = el.getBoundingClientRect();
|
||||
const grabOffset = e.clientY - rect.top;
|
||||
let pointerY = e.clientY;
|
||||
|
||||
const ph = el.cloneNode(true);
|
||||
ph.className = el.className + " " + placeholderClass;
|
||||
ph.removeAttribute("id");
|
||||
ph.setAttribute("aria-hidden", "true");
|
||||
ph.style.height = rect.height + "px";
|
||||
el.after(ph);
|
||||
|
||||
Object.assign(el.style, {
|
||||
position: "fixed",
|
||||
left: rect.left + "px",
|
||||
top: rect.top + "px",
|
||||
width: rect.width + "px",
|
||||
zIndex: "50",
|
||||
pointerEvents: "none",
|
||||
});
|
||||
el.classList.add("is-dragging");
|
||||
document.documentElement.classList.add("dragging-active");
|
||||
hdl.setPointerCapture(e.pointerId);
|
||||
|
||||
const place = () => {
|
||||
el.style.top = pointerY - grabOffset + "px";
|
||||
const others = children().filter((c) => c !== el && c !== ph);
|
||||
let before = null;
|
||||
for (const c of others) {
|
||||
const r = c.getBoundingClientRect();
|
||||
if (pointerY < r.top + r.height / 2) { before = c; break; }
|
||||
}
|
||||
if (before) {
|
||||
if (ph.nextElementSibling !== before) container.insertBefore(ph, before);
|
||||
} else if (container.lastElementChild !== ph) {
|
||||
container.append(ph);
|
||||
}
|
||||
};
|
||||
|
||||
// Scroll the page when dragging near the top or bottom edge.
|
||||
let raf = 0;
|
||||
const autoscroll = () => {
|
||||
const edge = 70;
|
||||
let dy = 0;
|
||||
if (pointerY < edge + 60) dy = -Math.ceil((edge + 60 - pointerY) / 6);
|
||||
else if (pointerY > innerHeight - edge) dy = Math.ceil((pointerY - (innerHeight - edge)) / 6);
|
||||
if (dy) { scrollBy(0, dy); place(); }
|
||||
raf = requestAnimationFrame(autoscroll);
|
||||
};
|
||||
raf = requestAnimationFrame(autoscroll);
|
||||
|
||||
const move = (ev) => { pointerY = ev.clientY; place(); };
|
||||
const end = () => {
|
||||
cancelAnimationFrame(raf);
|
||||
hdl.removeEventListener("pointermove", move);
|
||||
hdl.removeEventListener("pointerup", end);
|
||||
hdl.removeEventListener("pointercancel", end);
|
||||
ph.replaceWith(el);
|
||||
el.removeAttribute("style");
|
||||
el.classList.remove("is-dragging");
|
||||
document.documentElement.classList.remove("dragging-active");
|
||||
const to = children().indexOf(el);
|
||||
if (to !== from) onMove(el, from, to);
|
||||
};
|
||||
hdl.addEventListener("pointermove", move);
|
||||
hdl.addEventListener("pointerup", end);
|
||||
hdl.addEventListener("pointercancel", end);
|
||||
});
|
||||
|
||||
container.addEventListener("keydown", (e) => {
|
||||
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
||||
const hdl = e.target.closest(handle);
|
||||
if (!hdl) return;
|
||||
const el = children().find((c) => c.contains(hdl));
|
||||
const from = children().indexOf(el);
|
||||
const to = e.key === "ArrowUp" ? from - 1 : from + 1;
|
||||
if (to < 0 || to >= children().length) return;
|
||||
e.preventDefault();
|
||||
if (e.key === "ArrowUp") el.previousElementSibling.before(el);
|
||||
else el.nextElementSibling.after(el);
|
||||
hdl.focus();
|
||||
onMove(el, from, to);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user