mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Load more posts after post deletion
Closes #6390 - check if more posts should be loaded whenever one is deleted - delete dead code from posts controller - delete duplicate component gh-infinite-scroll-box - simplify posts-list-item `posts.post` or `editor.edit` link logic by modifying `gh-content-view-container` to yield necessary vars directly and use inline ifs in template - add `gh-tag` component for rendering tags and updating infinite scroll box on `settings/tags` page
This commit is contained in:
parent
7a36fd597f
commit
20cbc6c606
13 changed files with 44 additions and 71 deletions
|
@ -1,7 +0,0 @@
|
||||||
import Ember from 'ember';
|
|
||||||
import InfiniteScrollMixin from 'ghost/mixins/infinite-scroll';
|
|
||||||
|
|
||||||
const {Component} = Ember;
|
|
||||||
|
|
||||||
export default Component.extend(InfiniteScrollMixin, {
|
|
||||||
});
|
|
|
@ -3,4 +3,10 @@ import InfiniteScrollMixin from 'ghost/mixins/infinite-scroll';
|
||||||
|
|
||||||
const {Component} = Ember;
|
const {Component} = Ember;
|
||||||
|
|
||||||
export default Component.extend(InfiniteScrollMixin);
|
export default Component.extend(InfiniteScrollMixin, {
|
||||||
|
actions: {
|
||||||
|
checkScroll() {
|
||||||
|
this._checkScroll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -34,10 +34,6 @@ export default Component.extend(ActiveLinkWrapper, {
|
||||||
return Ember.String.htmlSafe(`background-image: url(${this.get('authorAvatar')})`);
|
return Ember.String.htmlSafe(`background-image: url(${this.get('authorAvatar')})`);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
viewOrEdit: computed('previewIsHidden', function () {
|
|
||||||
return this.get('previewIsHidden') ? 'editor.edit' : 'posts.post';
|
|
||||||
}),
|
|
||||||
|
|
||||||
click() {
|
click() {
|
||||||
this.sendAction('onClick', this.get('post'));
|
this.sendAction('onClick', this.get('post'));
|
||||||
},
|
},
|
||||||
|
@ -54,6 +50,9 @@ export default Component.extend(ActiveLinkWrapper, {
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
this.removeObserver('active', this, this.scrollIntoView);
|
this.removeObserver('active', this, this.scrollIntoView);
|
||||||
|
if (this.get('post.isDeleted') && this.attrs.onDelete) {
|
||||||
|
this.attrs.onDelete();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollIntoView() {
|
scrollIntoView() {
|
||||||
|
|
11
ghost/admin/app/components/gh-tag.js
Normal file
11
ghost/admin/app/components/gh-tag.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
willDestroyElement() {
|
||||||
|
this._super(...arguments);
|
||||||
|
|
||||||
|
if (this.get('tag.isDeleted') && this.attrs.onDelete) {
|
||||||
|
this.attrs.onDelete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -81,14 +81,6 @@ export default Controller.extend({
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showPostContent(post) {
|
|
||||||
if (!post) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.transitionToRoute('posts.post', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleDeletePostModal() {
|
toggleDeletePostModal() {
|
||||||
this.toggleProperty('showDeletePostModal');
|
this.toggleProperty('showDeletePostModal');
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,9 @@ export default Mixin.create({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if we are past a scroll point where we need to fetch the next page
|
* Determines if we are past a scroll point where we need to fetch the next page
|
||||||
* @param {object} event The scroll event
|
|
||||||
*/
|
*/
|
||||||
checkScroll(event) {
|
_checkScroll() {
|
||||||
let element = event.target;
|
let element = this.get('element');
|
||||||
let triggerPoint = this.get('triggerPoint');
|
let triggerPoint = this.get('triggerPoint');
|
||||||
let isLoading = this.get('isLoading');
|
let isLoading = this.get('isLoading');
|
||||||
|
|
||||||
|
@ -28,11 +27,11 @@ export default Mixin.create({
|
||||||
|
|
||||||
let el = this.get('element');
|
let el = this.get('element');
|
||||||
|
|
||||||
el.onscroll = run.bind(this, this.checkScroll);
|
el.onscroll = run.bind(this, this._checkScroll);
|
||||||
|
|
||||||
if (el.scrollHeight <= el.clientHeight) {
|
// run on load, on the offchance that the initial load
|
||||||
this.sendAction('fetch');
|
// did not fill the view.
|
||||||
}
|
this._checkScroll();
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{yield this}}
|
{{yield previewIsHidden}}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{{yield}}
|
|
|
@ -1 +1 @@
|
||||||
{{yield}}
|
{{yield (action "checkScroll")}}
|
||||||
|
|
8
ghost/admin/app/templates/components/gh-tag.hbs
Normal file
8
ghost/admin/app/templates/components/gh-tag.hbs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<div class="settings-tag">
|
||||||
|
{{#link-to 'settings.tags.tag' tag class="tag-edit-button"}}
|
||||||
|
<span class="tag-title">{{tag.name}}</span>
|
||||||
|
<span class="label label-default">/{{tag.slug}}</span>
|
||||||
|
<p class="tag-description">{{tag.description}}</p>
|
||||||
|
<span class="tags-count">{{tag.count.posts}}</span>
|
||||||
|
{{/link-to}}
|
||||||
|
</div>
|
|
@ -1,4 +1,4 @@
|
||||||
{{#gh-content-view-container as |container|}}
|
{{#gh-content-view-container as |previewIsHidden|}}
|
||||||
<header class="view-header">
|
<header class="view-header">
|
||||||
{{#gh-view-title openMobileMenu="openMobileMenu"}}<span>Content</span>{{/gh-view-title}}
|
{{#gh-view-title openMobileMenu="openMobileMenu"}}<span>Content</span>{{/gh-view-title}}
|
||||||
<section class="view-actions">
|
<section class="view-actions">
|
||||||
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
<div class="view-container">
|
<div class="view-container">
|
||||||
<section class="content-list js-content-list {{if postListFocused 'keyboard-focused'}}">
|
<section class="content-list js-content-list {{if postListFocused 'keyboard-focused'}}">
|
||||||
{{#gh-infinite-scroll-box tagName="section" classNames="content-list-content js-content-scrollbox" fetch="loadNextPage"}}
|
{{#gh-infinite-scroll tagName="section" classNames="content-list-content js-content-scrollbox" fetch="loadNextPage" as |checkScroll|}}
|
||||||
<ol class="posts-list">
|
<ol class="posts-list">
|
||||||
{{#each sortedPosts key="id" as |post|}}
|
{{#each sortedPosts key="id" as |post|}}
|
||||||
{{#gh-posts-list-item post=post onDoubleClick="openEditor" previewIsHidden=container.previewIsHidden as |component|}}
|
{{#gh-posts-list-item post=post onDoubleClick="openEditor" onDelete=(action checkScroll) as |component|}}
|
||||||
{{#link-to component.viewOrEdit post.id class="permalink" title="Edit this post"}}
|
{{#link-to (if previewIsHidden 'editor.edit' 'posts.post') post.id class="permalink" title="Edit this post"}}
|
||||||
<h3 class="entry-title">{{post.title}}</h3>
|
<h3 class="entry-title">{{post.title}}</h3>
|
||||||
<section class="entry-meta">
|
<section class="entry-meta">
|
||||||
<span class="avatar" style={{component.authorAvatarBackground}}>
|
<span class="avatar" style={{component.authorAvatarBackground}}>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
{{/gh-posts-list-item}}
|
{{/gh-posts-list-item}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ol>
|
</ol>
|
||||||
{{/gh-infinite-scroll-box}}
|
{{/gh-infinite-scroll}}
|
||||||
</section>
|
</section>
|
||||||
<section class="content-preview js-content-preview {{if postContentFocused 'keyboard-focused'}}">
|
<section class="content-preview js-content-preview {{if postContentFocused 'keyboard-focused'}}">
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
|
|
|
@ -12,17 +12,11 @@
|
||||||
fetch="loadNextPage"
|
fetch="loadNextPage"
|
||||||
isLoading=isLoading
|
isLoading=isLoading
|
||||||
classNames="tag-list"
|
classNames="tag-list"
|
||||||
|
as |checkScroll|
|
||||||
}}
|
}}
|
||||||
<section class="tag-list-content settings-tags {{if tagListFocused 'keyboard-focused'}}">
|
<section class="tag-list-content settings-tags {{if tagListFocused 'keyboard-focused'}}">
|
||||||
{{#each tags as |tag|}}
|
{{#each tags as |tag|}}
|
||||||
<div class="settings-tag">
|
{{gh-tag tag=tag onDelete=(action checkScroll)}}
|
||||||
{{#link-to 'settings.tags.tag' tag class="tag-edit-button"}}
|
|
||||||
<span class="tag-title">{{tag.name}}</span>
|
|
||||||
<span class="label label-default">/{{tag.slug}}</span>
|
|
||||||
<p class="tag-description">{{tag.description}}</p>
|
|
||||||
<span class="tags-count">{{tag.count.posts}}</span>
|
|
||||||
{{/link-to}}
|
|
||||||
</div>
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</section>
|
</section>
|
||||||
{{/gh-infinite-scroll}}
|
{{/gh-infinite-scroll}}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* jshint expr:true */
|
|
||||||
import {expect} from 'chai';
|
|
||||||
import {
|
|
||||||
describeComponent,
|
|
||||||
it
|
|
||||||
} from 'ember-mocha';
|
|
||||||
|
|
||||||
describeComponent(
|
|
||||||
'gh-infinite-scroll-box',
|
|
||||||
'Unit: Component: gh-infinite-scroll-box',
|
|
||||||
{
|
|
||||||
unit: true
|
|
||||||
// specify the other units that are required for this test
|
|
||||||
// needs: ['component:foo', 'helper:bar']
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
it('renders', function () {
|
|
||||||
// creates the component instance
|
|
||||||
let component = this.subject();
|
|
||||||
|
|
||||||
expect(component._state).to.equal('preRender');
|
|
||||||
|
|
||||||
// renders the component on the page
|
|
||||||
this.render();
|
|
||||||
expect(component._state).to.equal('inDOM');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
Loading…
Add table
Reference in a new issue