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.Body = buf.Bytes()
n.Save() 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) { func list(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value(middleware.ContextKey("user")).(string) user := r.Context().Value(middleware.ContextKey("user")).(string)
tag := r.FormValue("tag")
titlesAndUrls := make([]titleAndURL, 0) titlesAndUrls := make([]titleAndURL, 0)
ns := notes.Notes.Get(user) ns := notes.Notes.Get(user)
@ -206,10 +208,12 @@ func list(w http.ResponseWriter, r *http.Request) {
log.Printf("Notes for %s: %+v", user, ns) log.Printf("Notes for %s: %+v", user, ns)
for note := range ns { for note := range ns {
titlesAndUrls = append( if tag == "" || note.HasTag(tag) {
titlesAndUrls, titlesAndUrls = append(
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})}, titlesAndUrls,
) titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})},
)
}
} }
urlNew := myurls.Reverse("new", urls.Repl{}) urlNew := myurls.Reverse("new", urls.Repl{})