mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Added dynamic filter for resources
refs https://github.com/TryGhost/Team/issues/1572 - Depending on the state of the site, other resources are shown. - Also cleaned up error catching.
This commit is contained in:
parent
625635c6ed
commit
fdf425d95a
3 changed files with 18 additions and 6 deletions
|
@ -4,7 +4,6 @@
|
|||
<h4>Latest from the newsletter</h4>
|
||||
</div>
|
||||
<div class="gh-dashboard5-resource-body">
|
||||
|
||||
{{#if (not (or this.loading this.error))}}
|
||||
<div class="gh-dashboard5-resource-bigarticle">
|
||||
{{#each this.newsletters as |entry|}}
|
||||
|
@ -18,10 +17,9 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
<div class="gh-dashboard5-resource-footer">
|
||||
<a href="https://ghost.org/resources/newsletter/" target="_blank" class="gh-dashboard5-subscribe-button" rel="noopener noreferrer">Subscribe to the newsletter →</a>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class Newsletter extends Component {
|
|||
this.loading = true;
|
||||
this.fetch.perform().then(() => {
|
||||
this.loading = false;
|
||||
}, (error) => {
|
||||
}).catch((error) => {
|
||||
this.error = error;
|
||||
this.loading = false;
|
||||
});
|
||||
|
@ -40,5 +40,6 @@ export default class Newsletter extends Component {
|
|||
|
||||
let result = yield response.json();
|
||||
this.newsletters = result.posts || [];
|
||||
console.log(this.newsletters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,31 @@ export default class Resources extends Component {
|
|||
this.loading = true;
|
||||
this.fetch.perform().then(() => {
|
||||
this.loading = false;
|
||||
}, (error) => {
|
||||
}).catch((error) => {
|
||||
this.error = error;
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
get tag() {
|
||||
// Depending on the state of the site, we might want to show resources from different tags.
|
||||
if (this.areMembersEnabled && this.hasPaidTiers) {
|
||||
return 'business';
|
||||
}
|
||||
|
||||
if (this.areMembersEnabled) {
|
||||
return 'growth';
|
||||
}
|
||||
return 'building';
|
||||
}
|
||||
|
||||
@task
|
||||
*fetch() {
|
||||
const order = encodeURIComponent('published_at DESC');
|
||||
const key = encodeURIComponent(API_KEY);
|
||||
const limit = encodeURIComponent(RESOURCE_COUNT);
|
||||
let response = yield fetch(`${API_URL}/ghost/api/content/posts/?limit=${limit}&order=${order}&key=${key}&include=none`);
|
||||
const filter = encodeURIComponent('tag:'+this.tag);
|
||||
let response = yield fetch(`${API_URL}/ghost/api/content/posts/?limit=${limit}&order=${order}&key=${key}&include=none&filter=${filter}`);
|
||||
if (!response.ok) {
|
||||
// eslint-disable-next-line
|
||||
console.error('Failed to fetch resources', {response});
|
||||
|
|
Loading…
Add table
Reference in a new issue