Add item deactivation
This commit is contained in:
parent
76449d814f
commit
186f24e486
20
test/test_items.sh
Executable file
20
test/test_items.sh
Executable 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!"
|
@ -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;
|
||||
|
@ -1,6 +1,16 @@
|
||||
{{ define "item-buttons" -}}
|
||||
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">✕</button>
|
||||
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">↷</button>
|
||||
<button
|
||||
class="item-button"
|
||||
title="Deactivate {{ .Source }}/{{ .Id }}"
|
||||
hx-target="closest article"
|
||||
hx-swap="outerHTML"
|
||||
hx-select="article"
|
||||
hx-delete="/item/{{ .Source }}/{{ .Id }}"
|
||||
>✕</button>
|
||||
<button
|
||||
class="item-button"
|
||||
title="Punt {{ .Source }}/{{ .Id }}"
|
||||
>↷</button>
|
||||
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
@ -9,8 +19,13 @@
|
||||
<span class="item-title">{{ or .Title .Id | raw }}</span>
|
||||
{{- end }}
|
||||
|
||||
{{ define "item-class" -}}{{ if not .Active }}strikethru {{ end }}{{ if not .Active }}fade{{ end }}{{- end}}
|
||||
|
||||
{{ 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 */ -}}
|
||||
{{ if .Body }}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII=">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/htmx.org@2.0.4.js"></script>
|
||||
<meta name="htmx-config" content='{"ignoreTitle":true}'>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
|
17
web/item.go
17
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})
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user