Feature(template-gallery): add server-side pagination - #80
Conversation
- 9 templates per page, fetched page by page instead of loading the whole list - backend: /api/templates takes page/pageSize/q (search), sorts and paginates in mongo - frontend: port the upstream gallery pagination bar, move search onto its own row, center the category header, right-align the sort buttons
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c7940961d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .then(data => { | ||
| setLoadedTemplates(data.templates) | ||
| setVisibleTemplates(data.templates) | ||
| setTotalTemplatesCount(data.totalSize) |
There was a problem hiding this comment.
Ignore responses from superseded gallery requests
When page, sort, or debounced search parameters change before an earlier request finishes, every response still updates the same state. A slower obsolete request can therefore overwrite the latest response, leaving (for example) page 2's templates displayed while the pagination marks page 3 as current. Track the latest request or abort superseded requests before applying their results.
Useful? React with 👍 / 👎.
| // Must match the collation of the name indexes described in UPGRADE-6.3.md | ||
| // (created by the operator, see the upgrade notes), otherwise mongo falls | ||
| // back to an in-memory sort. | ||
| const NAME_COLLATION = { locale: 'en', strength: 2 } |
There was a problem hiding this comment.
Add the indexes referenced by the paginated query
The referenced UPGRADE-6.3.md does not exist anywhere in the repository, and the TemplateSchema defines no corresponding indexes. Consequently, both { lastUpdated, _id } and collation-aware { name, _id } sorts remain blocking sorts over the complete matching collection before skip and limit are applied, undermining server-side pagination and potentially spilling or failing on large galleries. Ship explicit operator upgrade instructions or migrations for the required compound indexes.
Useful? React with 👍 / 👎.
| aria-label={t('go_to_first_page')} | ||
| onClick={() => onPageChange(1)} | ||
| > | ||
| <span aria-hidden="true"><<</span> First |
There was a problem hiding this comment.
Translate the visible pagination labels
For every non-English locale, the new controls still visibly render the English words First, Prev, Next, and Last; only their screen-reader labels use translations. This regresses the localized gallery UI, so the visible labels should also use the existing i18n keys.
Useful? React with 👍 / 👎.
Description
Related issues / Pull Requests
Docs
Upgrading to Ayakaleaf Pro 6.3: Template Gallery indexes (optional)
The gallery now pages, sorts and searches in MongoDB. It works without any preparation; with thousands of templates, add these indexes to keep it fast (safe to re-run,
mongo/sharelatex= your container and database names):Keep the
collationon the two*_ciindexes as written — the galleryqueries with the same collation and MongoDB only uses a matching index.
Contributor Agreement