From 186f24e486188fdd28c7a3aba64c64fe82a8c256 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 27 Jan 2025 21:04:21 -0800 Subject: [PATCH] Add item deactivation --- test/test_items.sh | 20 ++++++++++++++++++++ web/html/intake.css | 6 +++--- web/html/item.html | 21 ++++++++++++++++++--- web/html/layout.html | 1 + web/item.go | 17 +++++++++++++++++ web/main.go | 1 + 6 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 test/test_items.sh diff --git a/test/test_items.sh b/test/test_items.sh new file mode 100755 index 0000000..a38b04c --- /dev/null +++ b/test/test_items.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -eu + +go build -o tmp/intake +rm "$1" || true +export INTAKE_DB="$1" +tmp/intake migrate +tmp/intake source add -s feedtest +tmp/intake item add -s feedtest --id "this-item-has-no-title" +tmp/intake item add -s feedtest --title "This item has only a title" +tmp/intake item add -s feedtest --title "Title and body" --body "This is the item body" +tmp/intake item add -s feedtest --title "Title and link" --link "#" +tmp/intake item add -s feedtest --title "Title, link, body" --link "#" --body "This is the body" +tmp/intake item add -s feedtest --title "HTML title" --link "#" --body "HTML body" +tmp/intake item add -s feedtest --title "Title and author" --author "Authorname" +tmp/intake item add -s feedtest --title "Title, author, time" --author "Authorname" --time 1700000000 +tmp/intake item add -s feedtest --title "Title, time" --time 1737780324 +tmp/intake item add -s feedtest --title "Title, author, body" --author "Authorname" --body "Hello body!" +tmp/intake item add -s feedtest --title "Title, author, time, body" --author "Authorname" --time 1700000000 --body "Hello body!" +tmp/intake item add -s feedtest --title "Title, time, body" --time 1737780324 --body "Hello, body!" diff --git a/web/html/intake.css b/web/html/intake.css index 1f2db51..f7f732b 100644 --- a/web/html/intake.css +++ b/web/html/intake.css @@ -27,7 +27,7 @@ article { border-radius: 2px; } .item-info { - color: rgba(0, 0, 0, 0.7); + opacity: 0.7; } details[open] > summary > .item-button, details[open] > summary > .item-link { display: none; @@ -58,8 +58,8 @@ summary:focus { width: 100%; resize: vertical; } -.fade span, .fade p { - color: rgba(0, 0, 0, 0.2); +.fade > * { + opacity: 0.2; } pre { white-space: pre-wrap; diff --git a/web/html/item.html b/web/html/item.html index c09b77b..dec336f 100644 --- a/web/html/item.html +++ b/web/html/item.html @@ -1,6 +1,16 @@ {{ define "item-buttons" -}} - - + + {{- if .Link }} {{ end -}} {{ end }} @@ -9,8 +19,13 @@ {{ or .Title .Id | raw }} {{- end }} +{{ define "item-class" -}}{{ if not .Active }}strikethru {{ end }}{{ if not .Active }}fade{{ end }}{{- end}} + {{ define "item" -}} -
+
{{- /* The item title is a clickable if there is body content */ -}} {{ if .Body }} diff --git a/web/html/layout.html b/web/html/layout.html index b9dbea4..8ce6704 100644 --- a/web/html/layout.html +++ b/web/html/layout.html @@ -6,6 +6,7 @@ +
diff --git a/web/item.go b/web/item.go index 57e6363..9a141f2 100644 --- a/web/item.go +++ b/web/item.go @@ -18,3 +18,20 @@ func (env *Env) getItem(writer http.ResponseWriter, req *http.Request) { } html.Item(writer, html.ItemData{Item: item}) } + +func (env *Env) deleteItem(writer http.ResponseWriter, req *http.Request) { + source := req.PathValue("source") + id := req.PathValue("id") + + _, err := core.DeactivateItem(env.db, source, id) + if err != nil { + writer.Write([]byte(err.Error())) + return + } + item, err := core.GetItem(env.db, source, id) + if err != nil { + writer.Write([]byte(err.Error())) + return + } + html.Item(writer, html.ItemData{Item: item}) +} diff --git a/web/main.go b/web/main.go index d4c18fd..b10c608 100644 --- a/web/main.go +++ b/web/main.go @@ -32,6 +32,7 @@ func RunServer(db *core.DB, addr string, port string) { handleFunc("GET /htmx.org@2.0.4.js", env.getScript) handleFunc("GET /source/{source}", env.getSource) handleFunc("GET /item/{source}/{id}", env.getItem) + handleFunc("DELETE /item/{source}/{id}", env.deleteItem) log.Fatal(http.ListenAndServe(bind, nil)) }