mirror of
https://github.com/flarum/framework.git
synced 2025-01-22 15:59:47 +08:00
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:
parent
f6c3834b32
commit
f375fd9241
35
framework/core/js/forum/dist/app.js
vendored
35
framework/core/js/forum/dist/app.js
vendored
|
@ -26700,13 +26700,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -26743,18 +26736,18 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
|
|||
var retain = this.subtree.retain();
|
||||
var count = this.count();
|
||||
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, {
|
||||
index: m(
|
||||
'span',
|
||||
{ className: 'Scrubber-index' },
|
||||
retain || formatNumber(this.commentsIndex)
|
||||
retain || formatNumber(Math.ceil(this.index + this.visible))
|
||||
),
|
||||
count: m(
|
||||
'span',
|
||||
{ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -26944,7 +26926,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
|
|||
// and the viewport had a height of 0.
|
||||
var $items = stream.$('> .PostStream-item[data-index]');
|
||||
var index = $items.first().data('index') || 0;
|
||||
var commentsIndex = 0;
|
||||
var visible = 0;
|
||||
var period = '';
|
||||
|
||||
|
@ -26956,13 +26937,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
|
|||
var top = $this.offset().top;
|
||||
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
|
||||
// one. If it's below the bottom of the viewport, break out of the
|
||||
// loop.
|
||||
|
@ -26994,7 +26968,6 @@ System.register('flarum/components/PostStreamScrubber', ['flarum/Component', 'fl
|
|||
});
|
||||
|
||||
this.index = index;
|
||||
this.commentsIndex = commentsIndex;
|
||||
this.visible = visible;
|
||||
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 $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.toggleClass('disabled', this.disabled());
|
||||
|
||||
|
|
|
@ -25,13 +25,6 @@ export default class PostStreamScrubber extends Component {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -65,11 +58,11 @@ export default class PostStreamScrubber extends Component {
|
|||
const retain = this.subtree.retain();
|
||||
const count = this.count();
|
||||
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, {
|
||||
index: <span className="Scrubber-index">{retain || formatNumber(this.commentsIndex)}</span>,
|
||||
count: <span className="Scrubber-count">{formatNumber(this.commentsCount())}</span>
|
||||
index: <span className="Scrubber-index">{retain || formatNumber(Math.ceil(this.index + this.visible))}</span>,
|
||||
count: <span className="Scrubber-count">{formatNumber(count)}</span>
|
||||
});
|
||||
|
||||
function styleUnread(element, isInitialized, context) {
|
||||
|
@ -152,15 +145,6 @@ export default class PostStreamScrubber extends Component {
|
|||
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.
|
||||
*/
|
||||
|
@ -214,7 +198,6 @@ export default class PostStreamScrubber extends Component {
|
|||
// and the viewport had a height of 0.
|
||||
const $items = stream.$('> .PostStream-item[data-index]');
|
||||
let index = $items.first().data('index') || 0;
|
||||
let commentsIndex = 0;
|
||||
let visible = 0;
|
||||
let period = '';
|
||||
|
||||
|
@ -226,13 +209,6 @@ export default class PostStreamScrubber extends Component {
|
|||
const top = $this.offset().top;
|
||||
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
|
||||
// one. If it's below the bottom of the viewport, break out of the
|
||||
// loop.
|
||||
|
@ -264,7 +240,6 @@ export default class PostStreamScrubber extends Component {
|
|||
});
|
||||
|
||||
this.index = index;
|
||||
this.commentsIndex = commentsIndex;
|
||||
this.visible = visible;
|
||||
this.description = period ? moment(period).format('MMMM YYYY') : '';
|
||||
}
|
||||
|
@ -340,7 +315,7 @@ export default class PostStreamScrubber extends Component {
|
|||
const visible = this.visible || 1;
|
||||
|
||||
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.toggleClass('disabled', this.disabled());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user