diff options
| -rw-r--r-- | walrss/internal/db/db.go | 15 | ||||
| -rw-r--r-- | walrss/internal/http/http.go | 2 | ||||
| -rw-r--r-- | walrss/internal/http/views/main.qtpl.html | 6 | ||||
| -rw-r--r-- | walrss/internal/http/views/main.qtpl.html.go | 10 |
4 files changed, 27 insertions, 6 deletions
diff --git a/walrss/internal/db/db.go b/walrss/internal/db/db.go index 5139af8..989038c 100644 --- a/walrss/internal/db/db.go +++ b/walrss/internal/db/db.go @@ -3,6 +3,7 @@ package db import ( "encoding/json" bh "github.com/timshannon/bolthold" + "strings" ) func New(filename string) (*bh.Store, error) { @@ -35,3 +36,17 @@ type Feed struct { Name string UserID string `boldholdIndex:"UserID"` } + +type FeedSlice []*Feed + +func (f FeedSlice) Len() int { + return len(f) +} + +func (f FeedSlice) Less(i, j int) bool { + return strings.ToLower(f[i].Name) < strings.ToLower(f[j].Name) +} + +func (f FeedSlice) Swap(i, j int) { + f[i], f[j] = f[j], f[i] +} diff --git a/walrss/internal/http/http.go b/walrss/internal/http/http.go index d0b1153..5d27cb2 100644 --- a/walrss/internal/http/http.go +++ b/walrss/internal/http/http.go @@ -60,10 +60,8 @@ func New(st *state.State) (*Server, error) { func (s *Server) registerHandlers() { s.app.Use(func(ctx *fiber.Ctx) error { if token := ctx.Cookies(sessionCookieKey); token != "" { - log.Debug().Msgf("cookie %s=%s", sessionCookieKey, token) userID, createdAt, err := core.ValidateSessionToken(token) if err == nil && time.Now().Sub(createdAt) < sessionDuration { - log.Debug().Msg("session valid") ctx.Locals(userIDLocalKey, userID) } } diff --git a/walrss/internal/http/views/main.qtpl.html b/walrss/internal/http/views/main.qtpl.html index fb5514b..5a9c523 100644 --- a/walrss/internal/http/views/main.qtpl.html +++ b/walrss/internal/http/views/main.qtpl.html @@ -1,5 +1,6 @@ {% import "github.com/codemicro/walrss/walrss/internal/db" %} {% import "github.com/codemicro/walrss/walrss/internal/urls" %} +{% import "sort" %} {% import "github.com/lithammer/shortuuid/v4" %} {% code type MainPage struct { @@ -7,7 +8,7 @@ EnableDigests bool SelectedDay db.SendDay SelectedTime int - Feeds []*db.Feed + Feeds db.FeedSlice } %} {% func (p *MainPage) Title() %}{% endfunc %} @@ -55,7 +56,7 @@ }) </script> -<div class="container"> +<div class="container pb-5"> <h1>My settings</h1> {%= p.RenderScheduleCard() %} @@ -87,6 +88,7 @@ </tr> </thead> <tbody id="feedListing"> + {% code sort.Sort(p.Feeds) %} {% for _, feed := range p.Feeds %} {%= RenderFeedRow(feed.ID, feed.Name, feed.URL) %} {% endfor %} diff --git a/walrss/internal/http/views/main.qtpl.html.go b/walrss/internal/http/views/main.qtpl.html.go index 4eb29c4..261c6f6 100644 --- a/walrss/internal/http/views/main.qtpl.html.go +++ b/walrss/internal/http/views/main.qtpl.html.go @@ -7,6 +7,8 @@ import "github.com/codemicro/walrss/walrss/internal/db" import "github.com/codemicro/walrss/walrss/internal/urls" +import "sort" + import "github.com/lithammer/shortuuid/v4" import ( @@ -25,7 +27,7 @@ type MainPage struct { EnableDigests bool SelectedDay db.SendDay SelectedTime int - Feeds []*db.Feed + Feeds db.FeedSlice } func (p *MainPage) StreamTitle(qw422016 *qt422016.Writer) { @@ -92,7 +94,7 @@ func (p *MainPage) StreamBody(qw422016 *qt422016.Writer) { }) </script> -<div class="container"> +<div class="container pb-5"> <h1>My settings</h1> `) @@ -129,6 +131,10 @@ func (p *MainPage) StreamBody(qw422016 *qt422016.Writer) { </thead> <tbody id="feedListing"> `) + sort.Sort(p.Feeds) + + qw422016.N().S(` + `) for _, feed := range p.Feeds { qw422016.N().S(` `) |
