Add unqueue (delete) button to web reading view

Adds a delete route and handler to the web UI so documents can be
removed directly from the reading page. Uses CSRF-protected POST with a
browser confirmation dialog. Styled with a danger accent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 00:08:45 -07:00
parent 940993a2e3
commit ed3a547e54
3 changed files with 22 additions and 0 deletions

View File

@@ -70,6 +70,7 @@ func (s *Server) RegisterRoutes(r chi.Router) {
r.Get("/d/{slug}", s.handleRead) r.Get("/d/{slug}", s.handleRead)
r.Post("/d/{slug}/read", s.handleMarkRead) r.Post("/d/{slug}/read", s.handleMarkRead)
r.Post("/d/{slug}/unread", s.handleMarkUnread) r.Post("/d/{slug}/unread", s.handleMarkUnread)
r.Post("/d/{slug}/delete", s.handleDelete)
r.Post("/logout", s.handleLogout) r.Post("/logout", s.handleLogout)
}) })
} }
@@ -176,3 +177,11 @@ func (s *Server) handleMarkUnread(w http.ResponseWriter, r *http.Request) {
} }
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
} }
func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
if err := s.db.DeleteDocument(slug); err != nil {
s.logger.Error("failed to delete document", "slug", slug, "error", err)
}
http.Redirect(w, r, "/", http.StatusFound)
}

View File

@@ -252,6 +252,14 @@ button:hover, .btn:hover {
padding: 0.1875rem 0.625rem; padding: 0.1875rem 0.625rem;
font-size: 0.75rem; font-size: 0.75rem;
} }
.btn-danger {
color: var(--accent);
border-color: var(--accent);
}
.btn-danger:hover {
background: var(--accent);
color: var(--bg);
}
/* =========================== /* ===========================
Forms Forms

View File

@@ -18,6 +18,11 @@
<button type="submit" class="btn-ghost btn btn-sm">Mark read</button> <button type="submit" class="btn-ghost btn btn-sm">Mark read</button>
</form> </form>
{{end}} {{end}}
<form method="POST" action="/d/{{.Doc.Slug}}/delete" style="display:inline"
onsubmit="return confirm('Delete this document?')">
{{csrfField}}
<button type="submit" class="btn-ghost btn btn-sm btn-danger">Unqueue</button>
</form>
<a href="/" class="btn-ghost btn btn-sm">Back to queue</a> <a href="/" class="btn-ghost btn btn-sm">Back to queue</a>
</div> </div>
</div> </div>