mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
A bit more cleanup and bugfixes
This commit is contained in:
committed by
Franz Liedke
parent
a850f4a6fb
commit
1d8662088f
@@ -105,16 +105,14 @@ export default class PostStream extends Component {
|
||||
if (this.state.needsScroll) {
|
||||
this.state.needsScroll = false;
|
||||
const locationType = this.state.locationType;
|
||||
if (this[locationType] != this.state[locationType]) {
|
||||
if (locationType == 'number') {
|
||||
this.scrollToNumber(this.state.number, this.state.noAnimationScroll);
|
||||
} else if (locationType == 'index') {
|
||||
const index = this.state.sanitizeIndex(this.state.index);
|
||||
const backwards = index == this.state.count() - 1;
|
||||
this.scrollToIndex(index, this.state.noAnimationScroll, backwards);
|
||||
}
|
||||
this[locationType] = this.state[locationType];
|
||||
if (locationType == 'number') {
|
||||
this.scrollToNumber(this.state.number, this.state.noAnimationScroll);
|
||||
} else if (locationType == 'index') {
|
||||
const index = this.state.sanitizeIndex(this.state.index);
|
||||
const backwards = index == this.state.count() - 1;
|
||||
this.scrollToIndex(index, this.state.noAnimationScroll, backwards);
|
||||
}
|
||||
this[locationType] = this.state[locationType];
|
||||
}
|
||||
|
||||
if (isInitialized) return;
|
||||
@@ -210,6 +208,11 @@ export default class PostStream extends Component {
|
||||
if (visiblePost > 0) {
|
||||
visible += visiblePost / height;
|
||||
}
|
||||
|
||||
// If this item has a time associated with it, then set the
|
||||
// scrollbar's current period to a formatted version of this time.
|
||||
const time = $this.data('time');
|
||||
if (time) period = time;
|
||||
});
|
||||
|
||||
this.state.index = index + 1;
|
||||
@@ -337,14 +340,14 @@ export default class PostStream extends Component {
|
||||
}
|
||||
|
||||
return Promise.all([$container.promise(), this.state.loadPromise]).then(() => {
|
||||
this.state.index = $item.data('index');
|
||||
console.log("loaded and scrolled");
|
||||
this.updateScrubber();
|
||||
this.state.index = $item.data('index');
|
||||
m.redraw(true);
|
||||
const scroll = this.state.index == 0 ? 0 : $(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop();
|
||||
$(window).scrollTop(scroll);
|
||||
this.calculatePosition();
|
||||
this.state.paused = false;
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -134,8 +134,8 @@ export default class PostStreamScrubber extends Component {
|
||||
}
|
||||
|
||||
config(isInitialized, context) {
|
||||
this.state.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true }));
|
||||
if (isInitialized) return;
|
||||
this.state.loadPromise.then(() => this.updateScrubberValues({ animate: true }));
|
||||
|
||||
context.onunload = this.ondestroy.bind(this);
|
||||
|
||||
@@ -277,28 +277,27 @@ export default class PostStreamScrubber extends Component {
|
||||
* @param {Boolean} animate
|
||||
*/
|
||||
updateScrubberValues(options = {}) {
|
||||
if (!options.fromScroll) console.log("hello")
|
||||
const index = this.state.index;
|
||||
const count = this.state.count();
|
||||
const visible = this.state.visible() || 1;
|
||||
const percentPerPost = this.percentPerPost();
|
||||
|
||||
const $scrubber = this.$();
|
||||
$scrubber.find(`.Scrubber-index`).text(formatNumber(this.state.sanitizeIndex(index + 1)));
|
||||
$scrubber.find(`.Scrubber-index`).text(formatNumber(this.state.sanitizeIndex(index)));
|
||||
$scrubber.find(`.Scrubber-description`).text(this.state.description);
|
||||
$scrubber.toggleClass('disabled', this.state.disabled());
|
||||
|
||||
const heights = {};
|
||||
heights.before = Math.max(0, percentPerPost.index * Math.min(index, count - visible));
|
||||
heights.before = Math.max(0, percentPerPost.index * Math.min(index - 1, count - visible));
|
||||
heights.handle = Math.min(100 - heights.before, percentPerPost.visible * visible);
|
||||
heights.after = 100 - heights.before - heights.handle;
|
||||
|
||||
console.log(heights.before + heights.after);
|
||||
|
||||
console.log("scrolling?");
|
||||
if (!(options.fromScroll && this.state.paused) && (!this.adjustingHeight || options.forceHeightChange)) {
|
||||
const func = options.animate ? 'animate' : 'css';
|
||||
this.adjustingHeight = true;
|
||||
const animationPromises = [];
|
||||
console.log("scrolling", heights.before, index)
|
||||
for (const part in heights) {
|
||||
const $part = $scrubber.find(`.Scrubber-${part}`);
|
||||
animationPromises.push(
|
||||
|
@@ -166,6 +166,7 @@ class PostStreamState {
|
||||
loadNearIndex(index) {
|
||||
console.log('loadNearIndex', index);
|
||||
if (index >= this.visibleStart && index <= this.visibleEnd) {
|
||||
console.log("doing the thing")
|
||||
return m.deferred().resolve().promise;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user