Ghost/ghost/admin/app/components/dashboard/v5/resources/newsletter.js
James Morris 58daafdef4 Further layout tweaks for new Dashboard (#2345)
* Subtle tweaks to the recent posts

refs: https://github.com/TryGhost/Team/issues/1531

* Combining Recent Posts and Members Activity together and other layout tweaks

refs: https://github.com/TryGhost/Team/issues/1531

- attempting to combine recent posts and members activity together
- various layout tweaks to make this work better
- tons of tiny style tweaks
2022-04-22 11:42:51 +01:00

44 lines
1.3 KiB
JavaScript

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 = 3;
export default class Newsletter 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 || [];
}
}