Add item deactivation

This commit is contained in:
Tim Van Baak 2025-01-27 21:04:21 -08:00
parent 76449d814f
commit 186f24e486
6 changed files with 60 additions and 6 deletions

20
test/test_items.sh Executable file
View File

@ -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 "<b>HTML title</b>" --link "#" --body "<i>HTML body</i>"
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!"

View File

@ -27,7 +27,7 @@ article {
border-radius: 2px; border-radius: 2px;
} }
.item-info { .item-info {
color: rgba(0, 0, 0, 0.7); opacity: 0.7;
} }
details[open] > summary > .item-button, details[open] > summary > .item-link { details[open] > summary > .item-button, details[open] > summary > .item-link {
display: none; display: none;
@ -58,8 +58,8 @@ summary:focus {
width: 100%; width: 100%;
resize: vertical; resize: vertical;
} }
.fade span, .fade p { .fade > * {
color: rgba(0, 0, 0, 0.2); opacity: 0.2;
} }
pre { pre {
white-space: pre-wrap; white-space: pre-wrap;

View File

@ -1,6 +1,16 @@
{{ define "item-buttons" -}} {{ define "item-buttons" -}}
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">&#10005;</button> <button
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">&#8631;</button> class="item-button"
title="Deactivate {{ .Source }}/{{ .Id }}"
hx-target="closest article"
hx-swap="outerHTML"
hx-select="article"
hx-delete="/item/{{ .Source }}/{{ .Id }}"
>&#10005;</button>
<button
class="item-button"
title="Punt {{ .Source }}/{{ .Id }}"
>&#8631;</button>
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">&#8663;</a> {{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">&#8663;</a>
{{ end -}} {{ end -}}
{{ end }} {{ end }}
@ -9,8 +19,13 @@
<span class="item-title">{{ or .Title .Id | raw }}</span> <span class="item-title">{{ or .Title .Id | raw }}</span>
{{- end }} {{- end }}
{{ define "item-class" -}}{{ if not .Active }}strikethru {{ end }}{{ if not .Active }}fade{{ end }}{{- end}}
{{ define "item" -}} {{ define "item" -}}
<article id="{{ .Source }}-{{ .Id }}"> <article
id="{{ .Source }}-{{ .Id }}"
class="{{ template "item-class" . }}"
>
{{- /* The item title is a clickable <summary> if there is body content */ -}} {{- /* The item title is a clickable <summary> if there is body content */ -}}
{{ if .Body }} {{ if .Body }}

View File

@ -6,6 +6,7 @@
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII="> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII=">
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
<script src="/htmx.org@2.0.4.js"></script> <script src="/htmx.org@2.0.4.js"></script>
<meta name="htmx-config" content='{"ignoreTitle":true}'>
</head> </head>
<body> <body>
<main> <main>

View File

@ -18,3 +18,20 @@ func (env *Env) getItem(writer http.ResponseWriter, req *http.Request) {
} }
html.Item(writer, html.ItemData{Item: item}) 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})
}

View File

@ -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 /htmx.org@2.0.4.js", env.getScript)
handleFunc("GET /source/{source}", env.getSource) handleFunc("GET /source/{source}", env.getSource)
handleFunc("GET /item/{source}/{id}", env.getItem) handleFunc("GET /item/{source}/{id}", env.getItem)
handleFunc("DELETE /item/{source}/{id}", env.deleteItem)
log.Fatal(http.ListenAndServe(bind, nil)) log.Fatal(http.ListenAndServe(bind, nil))
} }