Revert #687 + #197. fixes #785

Unfortunately we have no way to calculate the number of comment posts that are previous to the current viewing position of the discussion, without loading all of the posts which is going to be too expensive (even if we do it selectively somehow).
This commit is contained in:
Toby Zerner 2016-02-26 13:11:52 +10:30
parent f6c3834b32
commit f375fd9241
2 changed files with 8 additions and 60 deletions

View File

@ -26700,13 +26700,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
*/ */
this.index = 0; this.index = 0;
/**
* The index of the comment that is currently at the top of the viewport.
*
* @type {Number}
*/
this.commentsIndex = 0;
/** /**
* The number of posts that are currently visible in the viewport. * The number of posts that are currently visible in the viewport.
* *
@ -26743,18 +26736,18 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
var retain = this.subtree.retain(); var retain = this.subtree.retain();
var count = this.count(); var count = this.count();
var unreadCount = this.props.stream.discussion.unreadCount(); var unreadCount = this.props.stream.discussion.unreadCount();
var unreadPercent = Math.min(count - this.index, unreadCount) / count; var unreadPercent = count ? Math.min(count - this.index, unreadCount) / count : 0;
var viewing = app.translator.transChoice('core.forum.post_scrubber.viewing_text', count, { var viewing = app.translator.transChoice('core.forum.post_scrubber.viewing_text', count, {
index: m( index: m(
'span', 'span',
{ className: 'Scrubber-index' }, { className: 'Scrubber-index' },
retain || formatNumber(this.commentsIndex) retain || formatNumber(Math.ceil(this.index + this.visible))
), ),
count: m( count: m(
'span', 'span',
{ className: 'Scrubber-count' }, { className: 'Scrubber-count' },
formatNumber(this.commentsCount()) formatNumber(count)
) )
}); });
@ -26872,17 +26865,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
return this.props.stream.count(); return this.props.stream.count();
} }
/**
* Get the number of comments in the discussion.
*
* @return {Integer}
*/
}, {
key: 'commentsCount',
value: function commentsCount() {
return this.props.stream.discussion.commentsCount();
}
/** /**
* When the stream is unpaused, update the scrubber to reflect its position. * When the stream is unpaused, update the scrubber to reflect its position.
*/ */
@ -26944,7 +26926,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
// and the viewport had a height of 0. // and the viewport had a height of 0.
var $items = stream.$('> .PostStream-item[data-index]'); var $items = stream.$('> .PostStream-item[data-index]');
var index = $items.first().data('index') || 0; var index = $items.first().data('index') || 0;
var commentsIndex = 0;
var visible = 0; var visible = 0;
var period = ''; var period = '';
@ -26956,13 +26937,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
var top = $this.offset().top; var top = $this.offset().top;
var height = $this.outerHeight(true); var height = $this.outerHeight(true);
// If an item is a comment and is not below the viewport, update the
// comment index, which will be displayed as "viewing ? of X" on the
// scrubber.
if ($this.data('type') == 'comment' && top < viewportBottom) {
commentsIndex++;
}
// If this item is above the top of the viewport, skip to the next // If this item is above the top of the viewport, skip to the next
// one. If it's below the bottom of the viewport, break out of the // one. If it's below the bottom of the viewport, break out of the
// loop. // loop.
@ -26994,7 +26968,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
}); });
this.index = index; this.index = index;
this.commentsIndex = commentsIndex;
this.visible = visible; this.visible = visible;
this.description = period ? moment(period).format('MMMM YYYY') : ''; this.description = period ? moment(period).format('MMMM YYYY') : '';
} }
@ -27069,7 +27042,7 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
var visible = this.visible || 1; var visible = this.visible || 1;
var $scrubber = this.$(); var $scrubber = this.$();
$scrubber.find('.Scrubber-index').text(formatNumber(this.commentsIndex)); $scrubber.find('.Scrubber-index').text(formatNumber(Math.ceil(index + visible)));
$scrubber.find('.Scrubber-description').text(this.description); $scrubber.find('.Scrubber-description').text(this.description);
$scrubber.toggleClass('disabled', this.disabled()); $scrubber.toggleClass('disabled', this.disabled());

View File

@ -25,13 +25,6 @@ export default class PostStreamScrubber extends Component {
*/ */
this.index = 0; this.index = 0;
/**
* The index of the comment that is currently at the top of the viewport.
*
* @type {Number}
*/
this.commentsIndex = 0;
/** /**
* The number of posts that are currently visible in the viewport. * The number of posts that are currently visible in the viewport.
* *
@ -65,11 +58,11 @@ export default class PostStreamScrubber extends Component {
const retain = this.subtree.retain(); const retain = this.subtree.retain();
const count = this.count(); const count = this.count();
const unreadCount = this.props.stream.discussion.unreadCount(); const unreadCount = this.props.stream.discussion.unreadCount();
const unreadPercent = Math.min(count - this.index, unreadCount) / count; const unreadPercent = count ? Math.min(count - this.index, unreadCount) / count : 0;
const viewing = app.translator.transChoice('core.forum.post_scrubber.viewing_text', count, { const viewing = app.translator.transChoice('core.forum.post_scrubber.viewing_text', count, {
index: <span className="Scrubber-index">{retain || formatNumber(this.commentsIndex)}</span>, index: <span className="Scrubber-index">{retain || formatNumber(Math.ceil(this.index + this.visible))}</span>,
count: <span className="Scrubber-count">{formatNumber(this.commentsCount())}</span> count: <span className="Scrubber-count">{formatNumber(count)}</span>
}); });
function styleUnread(element, isInitialized, context) { function styleUnread(element, isInitialized, context) {
@ -152,15 +145,6 @@ export default class PostStreamScrubber extends Component {
return this.props.stream.count(); return this.props.stream.count();
} }
/**
* Get the number of comments in the discussion.
*
* @return {Integer}
*/
commentsCount() {
return this.props.stream.discussion.commentsCount();
}
/** /**
* When the stream is unpaused, update the scrubber to reflect its position. * When the stream is unpaused, update the scrubber to reflect its position.
*/ */
@ -214,7 +198,6 @@ export default class PostStreamScrubber extends Component {
// and the viewport had a height of 0. // and the viewport had a height of 0.
const $items = stream.$('> .PostStream-item[data-index]'); const $items = stream.$('> .PostStream-item[data-index]');
let index = $items.first().data('index') || 0; let index = $items.first().data('index') || 0;
let commentsIndex = 0;
let visible = 0; let visible = 0;
let period = ''; let period = '';
@ -226,13 +209,6 @@ export default class PostStreamScrubber extends Component {
const top = $this.offset().top; const top = $this.offset().top;
const height = $this.outerHeight(true); const height = $this.outerHeight(true);
// If an item is a comment and is not below the viewport, update the
// comment index, which will be displayed as "viewing ? of X" on the
// scrubber.
if ($this.data('type') == 'comment' && top < viewportBottom) {
commentsIndex++;
}
// If this item is above the top of the viewport, skip to the next // If this item is above the top of the viewport, skip to the next
// one. If it's below the bottom of the viewport, break out of the // one. If it's below the bottom of the viewport, break out of the
// loop. // loop.
@ -264,7 +240,6 @@ export default class PostStreamScrubber extends Component {
}); });
this.index = index; this.index = index;
this.commentsIndex = commentsIndex;
this.visible = visible; this.visible = visible;
this.description = period ? moment(period).format('MMMM YYYY') : ''; this.description = period ? moment(period).format('MMMM YYYY') : '';
} }
@ -340,7 +315,7 @@ export default class PostStreamScrubber extends Component {
const visible = this.visible || 1; const visible = this.visible || 1;
const $scrubber = this.$(); const $scrubber = this.$();
$scrubber.find('.Scrubber-index').text(formatNumber(this.commentsIndex)); $scrubber.find('.Scrubber-index').text(formatNumber(Math.ceil(index + visible)));
$scrubber.find('.Scrubber-description').text(this.description); $scrubber.find('.Scrubber-description').text(this.description);
$scrubber.toggleClass('disabled', this.disabled()); $scrubber.toggleClass('disabled', this.disabled());