1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-21 18:11:09 +00:00

Add optional sort option in category page

closes #1552
This commit is contained in:
Romain de Laage 2022-10-16 07:36:59 +02:00 committed by Frédéric Guillot
parent ec47106c26
commit 83e1f154b5
26 changed files with 131 additions and 13 deletions

View file

@ -112,6 +112,11 @@ func (s *Storage) Categories(userID int64) (model.Categories, error) {
// CategoriesWithFeedCount returns all categories with the number of feeds.
func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error) {
user, err := s.UserByID(userID)
if err != nil {
return nil, err
}
query := `
SELECT
c.id,
@ -126,11 +131,21 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error
FROM categories c
WHERE
user_id=$1
ORDER BY
count_unread DESC,
c.title ASC
`
if user.CategoriesSortOrder == "alphabetical" {
query = query + `
ORDER BY
c.title ASC
`
} else {
query = query + `
ORDER BY
count_unread DESC,
c.title ASC
`
}
rows, err := s.db.Query(query, userID)
if err != nil {
return nil, fmt.Errorf(`store: unable to fetch categories: %v`, err)