Support listing notes by tag

This commit is contained in:
Maximilian Friedersdorff 2025-11-05 08:46:22 +00:00
parent 105275f3e0
commit 95865257a3
2 changed files with 17 additions and 4 deletions

View file

@ -398,3 +398,12 @@ func (n *Note) ToggleBox(nthBox int) {
n.Body = buf.Bytes()
n.Save()
}
func (n *Note) HasTag(tag string) bool {
for _, tag_ := range n.Tags {
if tag_ == tag {
return true
}
}
return false
}

View file

@ -199,6 +199,8 @@ type titleAndURL struct {
func list(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value(middleware.ContextKey("user")).(string)
tag := r.FormValue("tag")
titlesAndUrls := make([]titleAndURL, 0)
ns := notes.Notes.Get(user)
@ -206,11 +208,13 @@ func list(w http.ResponseWriter, r *http.Request) {
log.Printf("Notes for %s: %+v", user, ns)
for note := range ns {
if tag == "" || note.HasTag(tag) {
titlesAndUrls = append(
titlesAndUrls,
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})},
)
}
}
urlNew := myurls.Reverse("new", urls.Repl{})