Преглед изворни кода

feat: add pagination to shared entries listing

Phantop пре 1 година
родитељ
комит
907941394b
2 измењених фајлова са 11 додато и 0 уклоњено
  1. 6 0
      internal/template/templates/views/shared_entries.html
  2. 5 0
      internal/ui/shared_entries.go

+ 6 - 0
internal/template/templates/views/shared_entries.html

@@ -33,6 +33,9 @@
 {{ if not .entries }}
     <p role="alert" class="alert alert-info">{{ t "alert.no_shared_entry" }}</p>
 {{ else }}
+    <div class="pagination-top">
+        {{ template "pagination" .pagination }}
+    </div>
     <div class="items">
         {{ range .entries }}
         <article
@@ -82,6 +85,9 @@
         </article>
         {{ end }}
     </div>
+    <div class="pagination-bottom">
+        {{ template "pagination" .pagination }}
+    </div>
 {{ end }}
 
 {{ end }}

+ 5 - 0
internal/ui/shared_entries.go

@@ -8,6 +8,7 @@ import (
 
 	"miniflux.app/v2/internal/http/request"
 	"miniflux.app/v2/internal/http/response/html"
+	"miniflux.app/v2/internal/http/route"
 	"miniflux.app/v2/internal/ui/session"
 	"miniflux.app/v2/internal/ui/view"
 )
@@ -19,9 +20,12 @@ func (h *handler) sharedEntries(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	offset := request.QueryIntParam(r, "offset", 0)
 	builder := h.store.NewEntryQueryBuilder(user.ID)
 	builder.WithShareCodeNotEmpty()
 	builder.WithSorting(user.EntryOrder, user.EntryDirection)
+	builder.WithOffset(offset)
+	builder.WithLimit(user.EntriesPerPage)
 
 	entries, err := builder.GetEntries()
 	if err != nil {
@@ -39,6 +43,7 @@ func (h *handler) sharedEntries(w http.ResponseWriter, r *http.Request) {
 	view := view.New(h.tpl, r, sess)
 	view.Set("entries", entries)
 	view.Set("total", count)
+	view.Set("pagination", getPagination(route.Path(h.router, "sharedEntries"), count, offset, user.EntriesPerPage))
 	view.Set("menu", "history")
 	view.Set("user", user)
 	view.Set("countUnread", h.store.CountUnreadEntries(user.ID))