Explorar o código

fix(ui): restart pagination when the feed or category page falls past the end

Marking a page as read shrinks the unread list under the current offset. On
the last page that leaves the offset past the end, and the template hides
pagination whenever there is nothing to render, so the view shows "no unread
entries" with no way back even though the header still reports the remaining
count. Reloading or reopening the URL keeps landing on the same dead end.

Fall back to the first page when the offset is past the end, which is what
showUnreadPage already does for the global unread view. A page that is still
within range is untouched, and a genuinely empty feed keeps its alert.
Aditya Raj Singh hai 1 mes
pai
achega
c52bdef6e9
Modificáronse 2 ficheiros con 48 adicións e 18 borrados
  1. 24 9
      internal/ui/category_entries.go
  2. 24 9
      internal/ui/feed_entries.go

+ 24 - 9
internal/ui/category_entries.go

@@ -33,20 +33,35 @@ func (h *handler) showCategoryEntriesPage(w http.ResponseWriter, r *http.Request
 
 
 	offset := request.QueryIntParam(r, "offset", 0)
 	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 {
 	if err != nil {
 		response.HTMLServerError(w, r, err)
 		response.HTMLServerError(w, r, err)
 		return
 		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 := view.New(h.tpl, r)
 	view.Set("category", category)
 	view.Set("category", category)
 	view.Set("total", count)
 	view.Set("total", count)

+ 24 - 9
internal/ui/feed_entries.go

@@ -33,20 +33,35 @@ func (h *handler) showFeedEntriesPage(w http.ResponseWriter, r *http.Request) {
 
 
 	offset := request.QueryIntParam(r, "offset", 0)
 	offset := request.QueryIntParam(r, "offset", 0)
 
 
-	entries, count, err := h.store.NewEntryQueryBuilder(user.ID).
-		WithFeedID(feed.ID).
-		WithStatuses(model.EntryStatusUnread).
-		WithSorting(user.EntryOrder, user.EntryDirection).
-		WithSorting("id", user.EntryDirection).
-		WithOffset(offset).
-		WithLimit(user.EntriesPerPage).
-		WithoutContent().
-		GetEntriesWithCount()
+	unreadEntries := func(offset int) (model.Entries, int, error) {
+		return h.store.NewEntryQueryBuilder(user.ID).
+			WithFeedID(feed.ID).
+			WithStatuses(model.EntryStatusUnread).
+			WithSorting(user.EntryOrder, user.EntryDirection).
+			WithSorting("id", user.EntryDirection).
+			WithOffset(offset).
+			WithLimit(user.EntriesPerPage).
+			WithoutContent().
+			GetEntriesWithCount()
+	}
+
+	entries, count, err := unreadEntries(offset)
 	if err != nil {
 	if err != nil {
 		response.HTMLServerError(w, r, err)
 		response.HTMLServerError(w, r, err)
 		return
 		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 := view.New(h.tpl, r)
 	view.Set("feed", feed)
 	view.Set("feed", feed)
 	view.Set("entries", entries)
 	view.Set("entries", entries)