mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FIX: Reply as new topic was broken when you quoted something
This commit is contained in:
parent
7e583a65a8
commit
a24afe30d7
@ -1,22 +1,25 @@
|
|||||||
var MAX_SHOWN = 5;
|
const MAX_SHOWN = 5;
|
||||||
|
|
||||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
import StringBuffer from 'discourse/mixins/string-buffer';
|
||||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
import { iconHTML } from 'discourse/helpers/fa-icon';
|
||||||
|
import property from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Em.Component.extend(StringBuffer, {
|
const { get, isEmpty, Component } = Ember;
|
||||||
|
|
||||||
|
export default Component.extend(StringBuffer, {
|
||||||
classNameBindings: [':gutter'],
|
classNameBindings: [':gutter'],
|
||||||
|
|
||||||
rerenderTriggers: ['expanded'],
|
rerenderTriggers: ['expanded'],
|
||||||
|
|
||||||
// Roll up links to avoid duplicates
|
// Roll up links to avoid duplicates
|
||||||
collapsed: function() {
|
@property('links')
|
||||||
var seen = {},
|
collapsed(links) {
|
||||||
result = [],
|
const seen = {};
|
||||||
links = this.get('links');
|
const result = [];
|
||||||
|
|
||||||
if (!Em.isEmpty(links)) {
|
if (!isEmpty(links)) {
|
||||||
links.forEach(function(l) {
|
links.forEach(function(l) {
|
||||||
var title = Em.get(l, 'title');
|
const title = get(l, 'title');
|
||||||
if (!seen[title]) {
|
if (!seen[title]) {
|
||||||
result.pushObject(l);
|
result.pushObject(l);
|
||||||
seen[title] = true;
|
seen[title] = true;
|
||||||
@ -24,52 +27,52 @@ export default Em.Component.extend(StringBuffer, {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}.property('links'),
|
},
|
||||||
|
|
||||||
renderString: function(buffer) {
|
renderString(buffer) {
|
||||||
var links = this.get('collapsed'),
|
const links = this.get('collapsed');
|
||||||
toRender = links,
|
const collapsed = !this.get('expanded');
|
||||||
collapsed = !this.get('expanded');
|
|
||||||
|
|
||||||
if (!Em.isEmpty(links)) {
|
if (!isEmpty(links)) {
|
||||||
|
let toRender = links;
|
||||||
if (collapsed) {
|
if (collapsed) {
|
||||||
toRender = toRender.slice(0, MAX_SHOWN);
|
toRender = toRender.slice(0, MAX_SHOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.push("<ul class='post-links'>");
|
buffer.push("<ul class='post-links'>");
|
||||||
toRender.forEach(function(l) {
|
toRender.forEach(function(l) {
|
||||||
var direction = Em.get(l, 'reflection') ? 'inbound' : 'outbound',
|
const direction = get(l, 'reflection') ? 'inbound' : 'outbound',
|
||||||
clicks = Em.get(l, 'clicks');
|
clicks = get(l, 'clicks');
|
||||||
|
|
||||||
buffer.push("<li><a href='" + Em.get(l, 'url') + "' class='track-link " + direction + "'>");
|
buffer.push(`<li><a href='${get(l, 'url')}' class='track-link ${direction}'>`);
|
||||||
|
|
||||||
var title = Em.get(l, 'title');
|
let title = get(l, 'title');
|
||||||
if (!Em.isEmpty(title)) {
|
if (!isEmpty(title)) {
|
||||||
title = Handlebars.Utils.escapeExpression(title);
|
title = Handlebars.Utils.escapeExpression(title);
|
||||||
buffer.push(Discourse.Emoji.unescape(title));
|
buffer.push(Discourse.Emoji.unescape(title));
|
||||||
}
|
}
|
||||||
if (clicks) {
|
if (clicks) {
|
||||||
buffer.push("<span class='badge badge-notification clicks'>" + clicks + "</span>");
|
buffer.push(`<span class='badge badge-notification clicks'>${clicks}</span>`);
|
||||||
}
|
}
|
||||||
buffer.push("</a></li>");
|
buffer.push("</a></li>");
|
||||||
});
|
});
|
||||||
|
|
||||||
if (collapsed) {
|
if (collapsed) {
|
||||||
var remaining = links.length - MAX_SHOWN;
|
const remaining = links.length - MAX_SHOWN;
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
buffer.push("<li><a href class='toggle-more'>" + I18n.t('post.more_links', {count: remaining}) + "</a></li>");
|
buffer.push(`<li><a href class='toggle-more'>${I18n.t('post.more_links', {count: remaining})}</a></li>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.push('</ul>');
|
buffer.push('</ul>');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.get('canReplyAsNewTopic')) {
|
if (this.get('canReplyAsNewTopic')) {
|
||||||
buffer.push("<a href class='reply-new'>" + iconHTML('plus') + I18n.t('post.reply_as_new_topic') + "</a>");
|
buffer.push(`<a href class='reply-new'>${iconHTML('plus')}${I18n.t('post.reply_as_new_topic')}</a>`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
click: function(e) {
|
click(e) {
|
||||||
var $target = $(e.target);
|
const $target = $(e.target);
|
||||||
if ($target.hasClass('toggle-more')) {
|
if ($target.hasClass('toggle-more')) {
|
||||||
this.toggleProperty('expanded');
|
this.toggleProperty('expanded');
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import loadScript from 'discourse/lib/load-script';
|
import loadScript from 'discourse/lib/load-script';
|
||||||
import Quote from 'discourse/lib/quote';
|
import Quote from 'discourse/lib/quote';
|
||||||
|
import property from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
needs: ['topic', 'composer'],
|
needs: ['topic', 'composer'],
|
||||||
@ -8,10 +9,15 @@ export default Ember.Controller.extend({
|
|||||||
loadScript('defer/html-sanitizer-bundle');
|
loadScript('defer/html-sanitizer-bundle');
|
||||||
}.on('init'),
|
}.on('init'),
|
||||||
|
|
||||||
// If the buffer is cleared, clear out other state (post)
|
@property('buffer', 'postId')
|
||||||
bufferChanged: function() {
|
post(buffer, postId) {
|
||||||
if (Ember.isEmpty(this.get('buffer'))) this.set('post', null);
|
if (!postId || Ember.isEmpty(buffer)) { return null; }
|
||||||
}.observes('buffer'),
|
|
||||||
|
const postStream = this.get('controllers.topic.model.postStream');
|
||||||
|
const post = postStream.findLoadedPost(postId);
|
||||||
|
|
||||||
|
return post;
|
||||||
|
},
|
||||||
|
|
||||||
// Save the currently selected text and displays the
|
// Save the currently selected text and displays the
|
||||||
// "quote reply" button
|
// "quote reply" button
|
||||||
@ -85,16 +91,13 @@ export default Ember.Controller.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
quoteText() {
|
quoteText() {
|
||||||
|
|
||||||
const postStream = this.get('controllers.topic.model.postStream');
|
|
||||||
const postId = this.get('postId');
|
const postId = this.get('postId');
|
||||||
const post = postStream.findLoadedPost(postId);
|
const post = this.get('post');
|
||||||
|
|
||||||
// defer load if needed, if in an expanded replies section
|
// defer load if needed, if in an expanded replies section
|
||||||
if (!post) {
|
if (!post) {
|
||||||
postStream.loadPost(postId).then(() => {
|
const postStream = this.get('controllers.topic.model.postStream');
|
||||||
this.quoteText();
|
postStream.loadPost(postId).then(() => this.quoteText());
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +113,7 @@ export default Ember.Controller.extend({
|
|||||||
draftKey: post.get('topic.draft_key')
|
draftKey: post.get('topic.draft_key')
|
||||||
};
|
};
|
||||||
|
|
||||||
if(post.get('post_number') === 1) {
|
if (post.get('post_number') === 1) {
|
||||||
composerOpts.topic = post.get("topic");
|
composerOpts.topic = post.get("topic");
|
||||||
} else {
|
} else {
|
||||||
composerOpts.post = post;
|
composerOpts.post = post;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user