From 0706d5f273cf71c352fc86f5edf021674a55c571 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Mon, 20 Feb 2023 12:27:01 +0100 Subject: [PATCH] Added pagination to mentions feed fixes https://github.com/TryGhost/Team/issues/2573 Adds infinite scrolling to the mentions feed. --- ghost/admin/app/controllers/mentions.js | 18 ++---------------- ghost/admin/app/routes/mentions.js | 17 ++++++++++++++--- ghost/admin/app/templates/mentions.hbs | 9 +++++++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ghost/admin/app/controllers/mentions.js b/ghost/admin/app/controllers/mentions.js index 968d644e50..fd7e4a08bc 100644 --- a/ghost/admin/app/controllers/mentions.js +++ b/ghost/admin/app/controllers/mentions.js @@ -1,21 +1,7 @@ import Controller from '@ember/controller'; -import {A} from '@ember/array'; -import {inject as service} from '@ember/service'; -import {task} from 'ember-concurrency'; -import {tracked} from '@glimmer/tracking'; export default class MentionsController extends Controller { - @service store; - - @tracked mentionsList = A([]); - - constructor() { - super(...arguments); - } - - @task - *loadMentionsTask() { - const mentions = yield this.store.query('mention', {order: 'created_at desc'}); - this.mentionsList = mentions; + get mentionsInfinityModel() { + return this.model; } } diff --git a/ghost/admin/app/routes/mentions.js b/ghost/admin/app/routes/mentions.js index fb356f832a..b5aa4cb78e 100644 --- a/ghost/admin/app/routes/mentions.js +++ b/ghost/admin/app/routes/mentions.js @@ -4,6 +4,9 @@ import {inject as service} from '@ember/service'; export default class MentionsRoute extends AuthenticatedRoute { @service store; @service feature; + @service infinity; + + perPage = 10; beforeModel() { super.beforeModel(...arguments); @@ -12,8 +15,16 @@ export default class MentionsRoute extends AuthenticatedRoute { } } - setupController(controller) { - super.setupController(...arguments); - controller.loadMentionsTask.perform(); + model() { + const perPage = this.perPage; + const paginationParams = { + perPageParam: 'limit', + totalPagesParam: 'meta.pagination.pages', + countParam: 'meta.pagination.total' + }; + + const paginationSettings = {perPage, startingPage: 1, order: 'created_at desc', ...paginationParams}; + + return this.infinity.model('mention', paginationSettings); } } diff --git a/ghost/admin/app/templates/mentions.hbs b/ghost/admin/app/templates/mentions.hbs index 838ea07db2..558b67f739 100644 --- a/ghost/admin/app/templates/mentions.hbs +++ b/ghost/admin/app/templates/mentions.hbs @@ -6,8 +6,8 @@
{{!-- TODO: Invert logic --}} - {{#if this.mentionsList}} - {{#each this.mentionsList as |mention|}} + {{#if this.mentionsInfinityModel}} + {{#each this.mentionsInfinityModel as |mention|}}
{{!-- TODO: link to the post analytics page of your post --}}

Your {{if (eq mention.resource.type "post") "post" "page"}} {{if mention.resource mention.resource.name mention.target}} was mentioned in:

@@ -45,5 +45,10 @@

When other sites mention your posts, they'll appear here.

{{/if}} + +