|
|
@@ -33,20 +33,35 @@ func (h *handler) showCategoryEntriesPage(w http.ResponseWriter, r *http.Request
|
|
|
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
|
|
|
|
|
- entries, count, err := h.store.NewEntryQueryBuilder(user.ID).
|
|
|
- WithCategoryID(category.ID).
|
|
|
- WithSorting(user.EntryOrder, user.EntryDirection).
|
|
|
- WithSorting("id", user.EntryDirection).
|
|
|
- WithStatuses(model.EntryStatusUnread).
|
|
|
- WithoutContent().
|
|
|
- WithOffset(offset).
|
|
|
- WithLimit(user.EntriesPerPage).
|
|
|
- GetEntriesWithCount()
|
|
|
+ unreadEntries := func(offset int) (model.Entries, int, error) {
|
|
|
+ return h.store.NewEntryQueryBuilder(user.ID).
|
|
|
+ WithCategoryID(category.ID).
|
|
|
+ WithSorting(user.EntryOrder, user.EntryDirection).
|
|
|
+ WithSorting("id", user.EntryDirection).
|
|
|
+ WithStatuses(model.EntryStatusUnread).
|
|
|
+ WithoutContent().
|
|
|
+ WithOffset(offset).
|
|
|
+ WithLimit(user.EntriesPerPage).
|
|
|
+ GetEntriesWithCount()
|
|
|
+ }
|
|
|
+
|
|
|
+ entries, count, err := unreadEntries(offset)
|
|
|
if err != nil {
|
|
|
response.HTMLServerError(w, r, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // Restart from the first page when marking entries as read leaves the offset past the end.
|
|
|
+ if offset >= count && count > 0 {
|
|
|
+ offset = 0
|
|
|
+
|
|
|
+ entries, count, err = unreadEntries(offset)
|
|
|
+ if err != nil {
|
|
|
+ response.HTMLServerError(w, r, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
view := view.New(h.tpl, r)
|
|
|
view.Set("category", category)
|
|
|
view.Set("total", count)
|