Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Delete comments

emanuele-emde696b59a79f
diff --git a/src/app.js b/src/app.js
index 10048bb..d3f62c0 100644
--- a/src/app.js
+++ b/src/app.js
@@ -643,10 +643,23 @@ async function refreshTask() {
$("#p-comments").replaceChildren(...comments.map((c) => {
const body = el("div", { class: "md" });
body.innerHTML = markdown(c.body);
- return el("div", { class: "comment" }, el("div", { class: "who" }, el("b", {}, c.author), " · ", timeEl(c.created_at)), body);
+ return el("div", { class: "comment" },
+ el("div", { class: "who" }, el("b", {}, c.author), " · ", timeEl(c.created_at),
+ el("button", { class: "remove", title: "Delete comment", "aria-label": "Delete comment",
+ onclick: () => deleteComment(c) }, icon("trash"))),
+ body);
}));
}
+async function deleteComment(c) {
+ if (!confirm("Delete this comment? This cannot be undone.")) return;
+ try {
+ await api("DELETE", `/comments/${c.id}`);
+ await refreshTask();
+ loadBoard();
+ } catch (err) { toast(err.message); }
+}
+
// The project tag doubles as a picker that moves the task to another project.
function renderProjectPick(task) {
const projects = state.board ? state.board.projects.map((p) => p.slug) : [];
diff --git a/src/index.html b/src/index.html
index e48d788..425a89a 100644
--- a/src/index.html
+++ b/src/index.html
@@ -211,7 +211,16 @@ header .sub a:hover { color: var(--text); }
.section h3 .count { color: var(--faint); font-weight: 400; }
.comment { padding: 10px 0; }
.comment:first-child { padding-top: 0; }
-.comment .who { font-size: 12px; color: var(--faint); margin-bottom: 2px; }
+.comment .who { font-size: 12px; color: var(--faint); margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }
+/* Each comment's delete button shows on hover, like the sidebar's "more" button. */
+.comment .remove {
+ margin-left: auto; padding: 3px; border: 0; border-radius: 6px; background: none; color: var(--faint);
+ visibility: hidden;
+}
+.comment:hover .remove, .comment .remove:focus-visible { visibility: visible; }
+.comment .remove:hover { color: var(--danger); background: var(--danger-bg); }
+.comment .remove .icon svg { width: 14px; height: 14px; }
+@media (hover: none) { .comment .remove { visibility: visible; } }
.comment .who b { color: var(--text); font-weight: 600; }
/* The comment box, with its send button inside like a chat composer. */
.composer { position: relative; margin-top: 6px; background: var(--field); border-radius: 20px; }
diff --git a/src/store.rs b/src/store.rs
index 5e07f38..c70506b 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -576,11 +576,12 @@ impl Store {
"INSERT INTO comments (task_id, author, body) VALUES (?1, ?2, ?3)",
params![task_id, author, body],
)?;
- let id = self.conn.last_insert_rowid();
- Ok(self.conn.query_row(
- "SELECT id, task_id, author, body, created_at FROM comments WHERE id = ?1",
- [id],
- |r| {
+ self.get_comment(self.conn.last_insert_rowid())
+ }
+
+ fn get_comment(&self, id: i64) -> Result<Comment> {
+ self.conn
+ .query_row("SELECT id, task_id, author, body, created_at FROM comments WHERE id = ?1", [id], |r| {
Ok(Comment {
id: r.get(0)?,
task_id: r.get(1)?,
@@ -588,8 +589,16 @@ impl Store {
body: r.get(3)?,
created_at: r.get(4)?,
})
- },
- )?)
+ })
+ .optional()?
+ .ok_or_else(|| Error::NotFound(format!("no comment {id}")))
+ }
+
+ /// Deletes a comment; returns it as it was.
+ pub fn delete_comment(&self, id: i64) -> Result<Comment> {
+ let comment = self.get_comment(id)?;
+ self.conn.execute("DELETE FROM comments WHERE id = ?1", [id])?;
+ Ok(comment)
}
}
@@ -718,6 +727,10 @@ mod tests {
assert_eq!(comments.iter().map(|c| c.author.as_str()).collect::<Vec<_>>(), ["claude-code", "me"]);
assert!(s.add_comment(t.id, "me", " ").is_err());
assert_eq!(s.get_task(t.id).unwrap().comments, 2);
+ let gone = s.add_comment(t.id, "me", "typo").unwrap();
+ assert_eq!(s.delete_comment(gone.id).unwrap().body, "typo");
+ assert!(s.delete_comment(gone.id).is_err());
+ assert_eq!(s.get_task(t.id).unwrap().comments, 2);
assert_eq!(s.find_project("api").unwrap().open, 1);
s.delete_task(t.id).unwrap();
diff --git a/src/web.rs b/src/web.rs
index 3270a48..1b87828 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -8,7 +8,7 @@ use axum::extract::{Path, Query, Request, State};
use axum::http::{HeaderValue, StatusCode, header};
use axum::middleware::{self, Next};
use axum::response::{Html, IntoResponse, Response};
-use axum::routing::{get, patch, post};
+use axum::routing::{delete, get, patch, post};
use axum::{Json, Router};
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -127,6 +127,7 @@ fn router(home: Home, guard: Guard, shutdown: CancellationToken) -> Router {
.route("/api/tasks/{id}", get(get_task).patch(update_task).delete(delete_task))
.route("/api/tasks/{id}/move", post(move_task))
.route("/api/tasks/{id}/comments", post(add_comment))
+ .route("/api/comments/{id}", delete(delete_comment))
.layer(middleware::from_fn_with_state(Arc::new(guard), protect))
.with_state(Arc::new(home))
}
@@ -354,6 +355,10 @@ async fn add_comment(State(home): Shared, Path(id): Path<i64>, Json(c): Json<New
with_store(home, move |_, s| s.add_comment(id, "me", &c.body)).await
}
+async fn delete_comment(State(home): Shared, Path(id): Path<i64>) -> Response {
+ with_store(home, move |_, s| s.delete_comment(id)).await
+}
+
/// True when the program on `port` answers like a Kanzo board.
async fn is_kanzo(port: u16) -> bool {
let probe = async {