mirror of
https://github.com/flarum/core.git
synced 2025-07-23 09:41:26 +02:00
Make sure discussion list subtrees don't go missing. Fixes #66
This commit is contained in:
@@ -65,7 +65,7 @@ export default class ComposerDiscussion extends ComposerBody {
|
|||||||
|
|
||||||
app.store.createRecord('discussions').save(data).then(discussion => {
|
app.store.createRecord('discussions').save(data).then(discussion => {
|
||||||
app.composer.hide();
|
app.composer.hide();
|
||||||
app.cache.discussionList.discussions().unshift(discussion);
|
app.cache.discussionList.addDiscussion(discussion);
|
||||||
m.route(app.route('discussion', { id: discussion.id(), slug: discussion.slug() }));
|
m.route(app.route('discussion', { id: discussion.id(), slug: discussion.slug() }));
|
||||||
}, response => {
|
}, response => {
|
||||||
this.loading(false);
|
this.loading(false);
|
||||||
|
@@ -24,10 +24,6 @@ export default class DiscussionList extends Component {
|
|||||||
app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this))
|
app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
addSubtrees(discussions) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
params() {
|
params() {
|
||||||
var params = {};
|
var params = {};
|
||||||
for (var i in this.props.params) {
|
for (var i in this.props.params) {
|
||||||
@@ -78,11 +74,15 @@ export default class DiscussionList extends Component {
|
|||||||
this.loadResults(this.discussions().length).then((results) => this.parseResults(results));
|
this.loadResults(this.discussions().length).then((results) => this.parseResults(results));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initSubtree(discussion) {
|
||||||
|
this.subtrees[discussion.id()] = new SubtreeRetainer(() => discussion.freshness);
|
||||||
|
}
|
||||||
|
|
||||||
parseResults(results) {
|
parseResults(results) {
|
||||||
m.startComputation();
|
m.startComputation();
|
||||||
this.loading(false);
|
this.loading(false);
|
||||||
|
|
||||||
results.forEach(discussion => this.subtrees[discussion.id()] = new SubtreeRetainer(() => discussion.freshness));
|
results.forEach(this.initSubtree.bind(this));
|
||||||
|
|
||||||
[].push.apply(this.discussions(), results);
|
[].push.apply(this.discussions(), results);
|
||||||
this.moreResults(!!results.payload.links.next);
|
this.moreResults(!!results.payload.links.next);
|
||||||
@@ -104,6 +104,11 @@ export default class DiscussionList extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addDiscussion(discussion) {
|
||||||
|
this.discussions().unshift(discussion);
|
||||||
|
this.initSubtree(discussion);
|
||||||
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
return m('div', [
|
return m('div', [
|
||||||
m('ul.discussions-list', [
|
m('ul.discussions-list', [
|
||||||
@@ -119,7 +124,7 @@ export default class DiscussionList extends Component {
|
|||||||
var active = m.route().substr(0, discussionRoute.length) === discussionRoute;
|
var active = m.route().substr(0, discussionRoute.length) === discussionRoute;
|
||||||
|
|
||||||
var subtree = this.subtrees[discussion.id()];
|
var subtree = this.subtrees[discussion.id()];
|
||||||
return m('li.discussion-summary'+(isUnread ? '.unread' : '')+(active ? '.active' : ''), {key: discussion.id(), 'data-id': discussion.id()}, subtree.retain() || m('div', [
|
return m('li.discussion-summary'+(isUnread ? '.unread' : '')+(active ? '.active' : ''), {key: discussion.id(), 'data-id': discussion.id()}, (subtree && subtree.retain()) || m('div', [
|
||||||
controls.length ? DropdownButton.component({
|
controls.length ? DropdownButton.component({
|
||||||
items: controls,
|
items: controls,
|
||||||
className: 'contextual-controls',
|
className: 'contextual-controls',
|
||||||
|
Reference in New Issue
Block a user