mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 00:54:50 +03:00
Added latest newsletters to dashboard 5.0
refs https://github.com/TryGhost/Team/issues/1488 - Includes a new component that fetches the latest X newsletters. - Displays these newsletters using design from old dashboard. - Currently shows 10 newsletters, but we'll want to change that later. - Temporary CSS class added.
This commit is contained in:
parent
811aa92394
commit
7833da8365
@ -90,6 +90,7 @@
|
||||
</section>
|
||||
|
||||
<Dashboard::V5::Resources::WhatsNew />
|
||||
<Dashboard::V5::Resources::LatestNewsletters />
|
||||
{{/if}}
|
||||
<Dashboard::V5::PrototypeControlPanel />
|
||||
</section>
|
||||
|
@ -0,0 +1,25 @@
|
||||
<div
|
||||
class="dashboard-prototype-newsletters"
|
||||
{{did-insert this.load}}
|
||||
>
|
||||
{{#if (not (or this.loading this.error))}}
|
||||
{{#each this.newsletters as |entry|}}
|
||||
<a class="gh-dashboard-container reverse" href={{set-query-params entry.url utm_source='admin'}} target="_blank" rel="noopener noreferrer">
|
||||
<div class="gh-dashboard-box blogpost">
|
||||
{{#if entry.feature_image}}
|
||||
<div class="thumbnail" style={{background-image-style entry.feature_image}}></div>
|
||||
{{/if}}
|
||||
<div class="content">
|
||||
<h2>{{entry.title}}</h2>
|
||||
{{#if entry.custom_excerpt}}
|
||||
<p>{{entry.custom_excerpt}}</p>
|
||||
{{else if entry.excerpt}}
|
||||
<p>{{entry.excerpt}}</p>
|
||||
{{/if}}
|
||||
<div class="read-time">{{entry.reading_time}} MIN READ</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
</div>
|
@ -0,0 +1,43 @@
|
||||
import Component from '@glimmer/component';
|
||||
import fetch from 'fetch';
|
||||
import {action} from '@ember/object';
|
||||
import {task} from 'ember-concurrency';
|
||||
import {tracked} from '@glimmer/tracking';
|
||||
|
||||
const API_URL = 'https://resources.ghost.io/resources';
|
||||
const API_KEY = 'b30afc1721f5d8d021ec3450ef';
|
||||
const NEWSLETTER_COUNT = 10;
|
||||
|
||||
export default class LatestNewsletters extends Component {
|
||||
@tracked loading = null;
|
||||
@tracked error = null;
|
||||
@tracked newsletters = null;
|
||||
|
||||
@action
|
||||
load() {
|
||||
this.loading = true;
|
||||
this.fetch.perform().then(() => {
|
||||
this.loading = false;
|
||||
}, (error) => {
|
||||
this.error = error;
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@task
|
||||
*fetch() {
|
||||
const order = encodeURIComponent('published_at DESC');
|
||||
const key = encodeURIComponent(API_KEY);
|
||||
const limit = encodeURIComponent(NEWSLETTER_COUNT);
|
||||
let response = yield fetch(`${API_URL}/ghost/api/content/posts/?limit=${limit}&order=${order}&key=${key}&include=none`);
|
||||
if (!response.ok) {
|
||||
// eslint-disable-next-line
|
||||
console.error('Failed to fetch newsletters', {response});
|
||||
this.error = 'Failed to fetch';
|
||||
return;
|
||||
}
|
||||
|
||||
let result = yield response.json();
|
||||
this.newsletters = result.posts || [];
|
||||
}
|
||||
}
|
34
ghost/admin/app/helpers/set-query-params.js
Normal file
34
ghost/admin/app/helpers/set-query-params.js
Normal file
@ -0,0 +1,34 @@
|
||||
import {helper} from '@ember/component/helper';
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
*
|
||||
* ```hbs
|
||||
* {{set-url-query 'https://myurl.com' utm_source='admin'}}
|
||||
* ```
|
||||
*
|
||||
* This example will return https://myurl.com?utm_source=admin
|
||||
*
|
||||
* You can set every query/search parameter you want. It will override existing paramters if they are already set.
|
||||
*/
|
||||
export function setQueryParams([url], parameters) {
|
||||
if (url) {
|
||||
// Do some magic
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
for (const key of Object.keys(parameters)) {
|
||||
parsed.searchParams.set(key, parameters[key]);
|
||||
}
|
||||
return parsed.href;
|
||||
} catch (e) {
|
||||
// Invalid url. Just pass the original.
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export default helper(setQueryParams);
|
@ -1579,6 +1579,11 @@ Dashboard v5 Section Anchor */
|
||||
/* ---------------------------------
|
||||
Dashboard v5 Section Growth */
|
||||
|
||||
/* Delete me */
|
||||
.dashboard-prototype-newsletters .gh-dashboard-container {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.gh-dashboard5-growth {
|
||||
display: flex;
|
||||
margin-top: -25px;
|
||||
|
Loading…
Reference in New Issue
Block a user