Drop zone now has three explicit visual states: empty (default cloud + instructions), ready (large file icon with a checkmark badge, filename in big, size + click-to-replace + remove button, solid emerald border and tinted background), and error (red icon + message, auto-clears after 2.5s). Covers both drag-drop and click-to-browse flows, validates size client-side, and scales up slightly during dragover. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
254 lines
12 KiB
HTML
254 lines
12 KiB
HTML
{{ define "dashboard" }}
|
|
{{ template "head" "Dashboard" }}
|
|
{{ template "header" true }}
|
|
<main class="max-w-6xl mx-auto px-6 py-8">
|
|
|
|
<!-- Stat tiles -->
|
|
<section class="grid grid-cols-2 md:grid-cols-4 gap-3 mb-8">
|
|
<div class="rounded border border-slate-800 bg-slate-900/50 px-4 py-3">
|
|
<div class="text-xs uppercase tracking-wide text-slate-400">Artifacts</div>
|
|
<div class="text-2xl font-semibold mt-1">{{ .Stats.TotalArtifacts }}</div>
|
|
</div>
|
|
<div class="rounded border border-slate-800 bg-slate-900/50 px-4 py-3">
|
|
<div class="text-xs uppercase tracking-wide text-slate-400">Views (7d)</div>
|
|
<div class="text-2xl font-semibold mt-1">{{ .Stats.Views7d }}</div>
|
|
</div>
|
|
<div class="rounded border border-slate-800 bg-slate-900/50 px-4 py-3">
|
|
<div class="text-xs uppercase tracking-wide text-slate-400">Views (30d)</div>
|
|
<div class="text-2xl font-semibold mt-1">{{ .Stats.Views30d }}</div>
|
|
</div>
|
|
<div class="rounded border border-slate-800 bg-slate-900/50 px-4 py-3">
|
|
<div class="text-xs uppercase tracking-wide text-slate-400">Storage</div>
|
|
<div class="text-2xl font-semibold mt-1">{{ humanSize .Stats.StorageBytes }}</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Publish form -->
|
|
<section class="rounded border border-slate-800 bg-slate-900/50 p-4 mb-8">
|
|
<h2 class="text-lg font-semibold mb-3">Publish</h2>
|
|
<form method="post" action="/api/publish" enctype="multipart/form-data" class="space-y-3" id="publishForm">
|
|
<label for="dropInput"
|
|
id="dropZone"
|
|
class="relative flex flex-col items-center justify-center text-center cursor-pointer
|
|
border-2 border-dashed border-slate-700 hover:border-indigo-500
|
|
rounded-lg bg-slate-950/50 hover:bg-slate-950
|
|
transition-[border-color,background-color,transform] duration-150
|
|
px-6 py-12 text-sm text-slate-400">
|
|
|
|
<!-- Empty state -->
|
|
<div class="flex flex-col items-center" data-state="empty">
|
|
<svg class="w-10 h-10 mb-3 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
|
|
d="M7 16a4 4 0 01-.88-7.9A5 5 0 0115.9 6.56 4 4 0 1118 16M8 13l4-4m0 0l4 4m-4-4v10"/>
|
|
</svg>
|
|
<div><span class="text-indigo-300 font-medium">Drop HTML file here</span> or click to browse</div>
|
|
<div class="text-xs text-slate-500 mt-1">.html · up to 5 MB</div>
|
|
</div>
|
|
|
|
<!-- Ready state (populated after a file is chosen) -->
|
|
<div class="hidden flex-col items-center w-full max-w-md" data-state="ready">
|
|
<div class="relative mb-3">
|
|
<svg class="w-12 h-12 text-emerald-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
|
|
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
|
</svg>
|
|
<span class="absolute -bottom-1 -right-1 inline-flex items-center justify-center w-5 h-5 rounded-full bg-emerald-500 text-slate-950 text-[10px] font-bold ring-2 ring-slate-900">✓</span>
|
|
</div>
|
|
<div class="flex items-center gap-2">
|
|
<span class="text-xs uppercase tracking-wider text-emerald-400 font-semibold">Ready</span>
|
|
<span class="w-1 h-1 rounded-full bg-slate-700"></span>
|
|
<span class="text-xs text-slate-500" id="dropSize">—</span>
|
|
</div>
|
|
<div class="font-medium text-slate-100 mt-1 truncate max-w-full" id="dropFilename">file.html</div>
|
|
<div class="text-xs text-slate-400 mt-2">
|
|
click to replace ·
|
|
<button type="button" id="dropClear" class="underline hover:text-slate-200">remove</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Error state -->
|
|
<div class="hidden flex-col items-center" data-state="error">
|
|
<svg class="w-10 h-10 mb-3 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
|
|
d="M12 9v2m0 4h.01M4.93 4.93l14.14 14.14M12 21a9 9 0 110-18 9 9 0 010 18z"/>
|
|
</svg>
|
|
<div class="text-red-300 font-medium" id="dropError">Only .html files are accepted</div>
|
|
<div class="text-xs text-slate-500 mt-1">try again</div>
|
|
</div>
|
|
|
|
<input id="dropInput" type="file" name="file" accept=".html,text/html" class="sr-only" required>
|
|
</label>
|
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-3">
|
|
<label class="block">
|
|
<span class="block text-xs text-slate-400 mb-1">Custom slug (optional)</span>
|
|
<input type="text" name="slug" pattern="[a-z0-9][a-z0-9-]{2,31}" placeholder="auto"
|
|
class="w-full bg-slate-950 border border-slate-800 rounded px-3 py-2 text-sm">
|
|
</label>
|
|
<label class="block">
|
|
<span class="block text-xs text-slate-400 mb-1">Title (optional)</span>
|
|
<input type="text" name="title" placeholder="from <title> if blank"
|
|
class="w-full bg-slate-950 border border-slate-800 rounded px-3 py-2 text-sm">
|
|
</label>
|
|
<label class="block">
|
|
<span class="block text-xs text-slate-400 mb-1">Password (optional)</span>
|
|
<input type="password" name="password" autocomplete="new-password"
|
|
class="w-full bg-slate-950 border border-slate-800 rounded px-3 py-2 text-sm">
|
|
</label>
|
|
<label class="block">
|
|
<span class="block text-xs text-slate-400 mb-1">Expires</span>
|
|
<select name="expires_in" class="w-full bg-slate-950 border border-slate-800 rounded px-3 py-2 text-sm">
|
|
<option value="never">never</option>
|
|
<option value="1h">1 hour</option>
|
|
<option value="24h">1 day</option>
|
|
<option value="7d">7 days</option>
|
|
<option value="30d">30 days</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<div class="flex items-center justify-end">
|
|
<button class="bg-indigo-600 hover:bg-indigo-500 text-white rounded px-4 py-2 font-medium text-sm">Publish</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<script>
|
|
(function () {
|
|
const zone = document.getElementById('dropZone');
|
|
const input = document.getElementById('dropInput');
|
|
const filename = document.getElementById('dropFilename');
|
|
const sizeEl = document.getElementById('dropSize');
|
|
const errorEl = document.getElementById('dropError');
|
|
const clearBtn = document.getElementById('dropClear');
|
|
if (!zone || !input) return;
|
|
|
|
const panels = {
|
|
empty: zone.querySelector('[data-state="empty"]'),
|
|
ready: zone.querySelector('[data-state="ready"]'),
|
|
error: zone.querySelector('[data-state="error"]'),
|
|
};
|
|
|
|
const READY = ['border-emerald-500', '!border-solid', 'bg-emerald-500/5'];
|
|
const OVER = ['border-indigo-500', 'bg-indigo-500/10', 'scale-[1.01]'];
|
|
const ERROR = ['border-red-500', 'bg-red-500/5'];
|
|
|
|
function setState(name) {
|
|
for (const key of Object.keys(panels)) {
|
|
const show = key === name;
|
|
panels[key].classList.toggle('hidden', !show);
|
|
panels[key].classList.toggle('flex', show);
|
|
}
|
|
zone.classList.remove(...READY, ...OVER, ...ERROR);
|
|
if (name === 'ready') zone.classList.add(...READY);
|
|
else if (name === 'error') zone.classList.add(...ERROR);
|
|
}
|
|
|
|
const prevent = e => { e.preventDefault(); e.stopPropagation(); };
|
|
['dragenter', 'dragover'].forEach(ev =>
|
|
zone.addEventListener(ev, e => { prevent(e); zone.classList.add(...OVER); }));
|
|
['dragleave', 'drop'].forEach(ev =>
|
|
zone.addEventListener(ev, e => { prevent(e); zone.classList.remove(...OVER); }));
|
|
|
|
zone.addEventListener('drop', e => {
|
|
const f = e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files[0];
|
|
if (!f) return;
|
|
handleFile(f);
|
|
});
|
|
|
|
input.addEventListener('change', () => {
|
|
const f = input.files && input.files[0];
|
|
if (f) handleFile(f);
|
|
});
|
|
|
|
clearBtn && clearBtn.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
input.value = '';
|
|
setState('empty');
|
|
});
|
|
|
|
function handleFile(f) {
|
|
if (!/\.html?$/i.test(f.name) && f.type !== 'text/html') {
|
|
errorEl.textContent = `Not an HTML file: ${f.name}`;
|
|
setState('error');
|
|
setTimeout(() => { if (!input.files[0]) setState('empty'); }, 2500);
|
|
return;
|
|
}
|
|
if (f.size > 5 * 1024 * 1024) {
|
|
errorEl.textContent = `Too large (${fmtSize(f.size)}, max 5 MB)`;
|
|
setState('error');
|
|
return;
|
|
}
|
|
// Reflect drop selection back into the input so the form submits it.
|
|
try {
|
|
const dt = new DataTransfer();
|
|
dt.items.add(f);
|
|
input.files = dt.files;
|
|
} catch (_) { /* no-op: input.files already set if via click */ }
|
|
filename.textContent = f.name;
|
|
sizeEl.textContent = fmtSize(f.size);
|
|
setState('ready');
|
|
}
|
|
|
|
function fmtSize(n) {
|
|
if (n < 1024) return `${n} B`;
|
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
{{ if .FlashSlug }}
|
|
<div class="rounded border border-emerald-800 bg-emerald-900/30 text-emerald-100 px-4 py-3 mb-6 text-sm flex items-center justify-between">
|
|
<div>
|
|
Published: <code class="bg-slate-900 px-2 py-0.5 rounded">{{ .BaseURL }}/p/{{ .FlashSlug }}</code>
|
|
</div>
|
|
<button onclick="navigator.clipboard.writeText('{{ .BaseURL }}/p/{{ .FlashSlug }}')"
|
|
class="bg-emerald-700 hover:bg-emerald-600 rounded px-3 py-1 text-xs">Copy link</button>
|
|
</div>
|
|
{{ end }}
|
|
|
|
<!-- Artifact list -->
|
|
<section class="rounded border border-slate-800 bg-slate-900/30 overflow-hidden">
|
|
<table class="w-full text-sm">
|
|
<thead class="bg-slate-900 text-slate-400 text-xs uppercase tracking-wide">
|
|
<tr>
|
|
<th class="text-left px-4 py-2">Slug</th>
|
|
<th class="text-left px-4 py-2">Title</th>
|
|
<th class="text-right px-4 py-2">Views</th>
|
|
<th class="text-left px-4 py-2">Last viewed</th>
|
|
<th class="text-left px-4 py-2">7-day</th>
|
|
<th class="text-left px-4 py-2">Size</th>
|
|
<th class="text-right px-4 py-2">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{ range .Items }}
|
|
<tr id="row-{{ .Slug }}" class="border-t border-slate-800 hover:bg-slate-900/50">
|
|
<td class="px-4 py-2">
|
|
<a class="font-mono text-indigo-300 hover:text-indigo-200" href="/a/{{ .Slug }}">{{ .Slug }}</a>
|
|
{{ if .HasPassword }}<span class="ml-1 text-xs text-amber-400" title="Password-protected">🔒</span>{{ end }}
|
|
</td>
|
|
<td class="px-4 py-2 text-slate-300">{{ if .Title }}{{ .Title }}{{ else }}<span class="text-slate-500">—</span>{{ end }}</td>
|
|
<td class="px-4 py-2 text-right tabular-nums">{{ .ViewCount }}</td>
|
|
<td class="px-4 py-2 text-slate-400">{{ humanTime .LastViewedAt }}</td>
|
|
<td class="px-4 py-2 spark text-indigo-300">{{ sparkline .Spark }}</td>
|
|
<td class="px-4 py-2 text-slate-400">{{ humanSize .SizeBytes }}</td>
|
|
<td class="px-4 py-2 text-right">
|
|
<button onclick="navigator.clipboard.writeText('{{ $.BaseURL }}/p/{{ .Slug }}')"
|
|
class="text-xs px-2 py-1 rounded bg-slate-800 hover:bg-slate-700">Copy</button>
|
|
<a href="/p/{{ .Slug }}" target="_blank" class="text-xs px-2 py-1 rounded bg-slate-800 hover:bg-slate-700">Open</a>
|
|
<button hx-delete="/a/{{ .Slug }}" hx-target="#row-{{ .Slug }}" hx-swap="outerHTML"
|
|
hx-confirm="Delete {{ .Slug }}? This cannot be undone."
|
|
class="text-xs px-2 py-1 rounded bg-red-900/60 hover:bg-red-800">Delete</button>
|
|
</td>
|
|
</tr>
|
|
{{ else }}
|
|
<tr><td colspan="7" class="px-4 py-10 text-center text-slate-500">No artifacts yet. Paste some HTML above to publish your first one.</td></tr>
|
|
{{ end }}
|
|
</tbody>
|
|
</table>
|
|
</section>
|
|
</main>
|
|
{{ template "footer" }}
|
|
{{ end }}
|