Generalize pagination to work with things other than search

This commit is contained in:
2020-12-21 22:30:14 -08:00
parent c5ebcef2c8
commit 54be576a8c
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -20,11 +20,12 @@ module.exports.GET = async (req, res) => {
}
// Search, if we have a query.
const path = `/search?q=${url.search.q}&`
const {limit, offset} = pagination.getValuesToPaginate({ currentPage: p, perPage: PER_PAGE })
const results = await ds.search(db, q, limit, offset)
const count = await ds.searchCount(db, q)
const totalPages = pagination.getTotalPages({ totalItems: count, perPage: PER_PAGE })
const out = await page.render('search', { q, rawQ: url.search.q, p, results, count, totalPages })
const out = await page.render('search', { path, q, p, results, count, totalPages })
return send(res, 200, out)
//return send(res, 200, { results, count })
+1 -1
View File
@@ -8,7 +8,7 @@
<% if (i == p) { %>
<span><%- i %></span>&nbsp;
<% } else { %>
<a href="/search?q=<%= q %>&p=<%= i %>"><%- i %></a>&nbsp;
<a href="<%- path %>p=<%= i %>"><%- i %></a>&nbsp;
<% } %>
<% } %>
</div>