0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Wired up mentions API to post analytics

refs https://github.com/TryGhost/Team/issues/2575
This commit is contained in:
Simon Backx 2023-02-21 11:46:16 +01:00
parent 097416ba19
commit 1ef4690c7b
2 changed files with 41 additions and 8 deletions

View file

@ -127,18 +127,26 @@
{{/if}}
{{/if}}
{{#if (feature 'webmentions')}}
{{#if this.showMentions }}
<div class="pa4">
<h3>Mentions</h3>
<div>
<div>
<div class="flex">
<img src="assets/img/orb-squircle.png" alt="Ghost" class="w5 h5 mr2 flex-shrink-0" />
<div class="flex flex-column">
<span class="gh-dashboard-list-text">How to do stuff</span>
<span>2 days ago</span>
{{#if this.mentions}}
{{#each this.mentions as |mention|}}
<div class="flex">
<img src="assets/img/orb-squircle.png" alt="Ghost" class="w5 h5 mr2 flex-shrink-0" />
<div class="flex flex-column">
<span class="gh-dashboard-list-text">{{if mention.sourceSiteTitle mention.sourceSiteTitle mention.source}}</span>
<span>{{moment-from-now mention.timestamp}}</span>
</div>
</div>
{{/each}}
{{else}}
<div>
<p>No mentions yet.</p>
</div>
</div>
{{/if}}
</div>
</div>
<a href="#">See all mentions</a>

View file

@ -23,9 +23,11 @@ export default class Analytics extends Component {
@service membersUtils;
@service utils;
@service feature;
@service store;
@tracked sources = null;
@tracked links = null;
@tracked mentions = null;
@tracked sortColumn = 'signups';
@tracked showSuccess;
@tracked updateLinkId;
@ -132,6 +134,12 @@ export default class Analytics extends Component {
} else {
this.links = [];
}
if (this.showMentions) {
this.fetchMentions();
} else {
this.mentions = [];
}
}
updateLinkData(linksData) {
@ -269,6 +277,19 @@ export default class Analytics extends Component {
this.updateLinkData(result.links);
}
async fetchMentions() {
if (this._fetchMentions.isRunning) {
return this._fetchMentions.last;
}
return this._fetchMentions.perform();
}
@task
*_fetchMentions() {
const filter = `resource_id:${this.post.id}+resource_type:post`;
this.mentions = yield this.store.query('mention', {limit: 5, order: 'created_at desc', filter});
}
get showLinks() {
return this.post.showEmailClickAnalytics;
}
@ -277,7 +298,11 @@ export default class Analytics extends Component {
return this.feature.get('sourceAttribution') && this.post.showAttributionAnalytics;
}
get showMentions() {
return this.feature.get('webmentions');
}
get isLoaded() {
return this.links !== null && this.souces !== null;
return this.links !== null && this.souces !== null && this.mentions !== null;
}
}