1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 17:36:38 +02:00

A bit more cleanup and bugfixes

This commit is contained in:
Alexander Skvortsov
2020-07-09 21:31:43 -04:00
committed by Franz Liedke
parent a850f4a6fb
commit 1d8662088f
3 changed files with 20 additions and 17 deletions

View File

@@ -105,16 +105,14 @@ export default class PostStream extends Component {
if (this.state.needsScroll) { if (this.state.needsScroll) {
this.state.needsScroll = false; this.state.needsScroll = false;
const locationType = this.state.locationType; const locationType = this.state.locationType;
if (this[locationType] != this.state[locationType]) { if (locationType == 'number') {
if (locationType == 'number') { this.scrollToNumber(this.state.number, this.state.noAnimationScroll);
this.scrollToNumber(this.state.number, this.state.noAnimationScroll); } else if (locationType == 'index') {
} else if (locationType == 'index') { const index = this.state.sanitizeIndex(this.state.index);
const index = this.state.sanitizeIndex(this.state.index); const backwards = index == this.state.count() - 1;
const backwards = index == this.state.count() - 1; this.scrollToIndex(index, this.state.noAnimationScroll, backwards);
this.scrollToIndex(index, this.state.noAnimationScroll, backwards);
}
this[locationType] = this.state[locationType];
} }
this[locationType] = this.state[locationType];
} }
if (isInitialized) return; if (isInitialized) return;
@@ -210,6 +208,11 @@ export default class PostStream extends Component {
if (visiblePost > 0) { if (visiblePost > 0) {
visible += visiblePost / height; 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; this.state.index = index + 1;
@@ -337,14 +340,14 @@ export default class PostStream extends Component {
} }
return Promise.all([$container.promise(), this.state.loadPromise]).then(() => { return Promise.all([$container.promise(), this.state.loadPromise]).then(() => {
this.state.index = $item.data('index'); console.log("loaded and scrolled");
this.updateScrubber(); this.updateScrubber();
this.state.index = $item.data('index');
m.redraw(true); m.redraw(true);
const scroll = this.state.index == 0 ? 0 : $(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop(); const scroll = this.state.index == 0 ? 0 : $(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop();
$(window).scrollTop(scroll); $(window).scrollTop(scroll);
this.calculatePosition(); this.calculatePosition();
this.state.paused = false; this.state.paused = false;
m.redraw();
}); });
} }

View File

@@ -134,8 +134,8 @@ export default class PostStreamScrubber extends Component {
} }
config(isInitialized, context) { config(isInitialized, context) {
this.state.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true }));
if (isInitialized) return; if (isInitialized) return;
this.state.loadPromise.then(() => this.updateScrubberValues({ animate: true }));
context.onunload = this.ondestroy.bind(this); context.onunload = this.ondestroy.bind(this);
@@ -277,28 +277,27 @@ export default class PostStreamScrubber extends Component {
* @param {Boolean} animate * @param {Boolean} animate
*/ */
updateScrubberValues(options = {}) { updateScrubberValues(options = {}) {
if (!options.fromScroll) console.log("hello")
const index = this.state.index; const index = this.state.index;
const count = this.state.count(); const count = this.state.count();
const visible = this.state.visible() || 1; const visible = this.state.visible() || 1;
const percentPerPost = this.percentPerPost(); const percentPerPost = this.percentPerPost();
const $scrubber = this.$(); 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.find(`.Scrubber-description`).text(this.state.description);
$scrubber.toggleClass('disabled', this.state.disabled()); $scrubber.toggleClass('disabled', this.state.disabled());
const heights = {}; 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.handle = Math.min(100 - heights.before, percentPerPost.visible * visible);
heights.after = 100 - heights.before - heights.handle; 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)) { if (!(options.fromScroll && this.state.paused) && (!this.adjustingHeight || options.forceHeightChange)) {
const func = options.animate ? 'animate' : 'css'; const func = options.animate ? 'animate' : 'css';
this.adjustingHeight = true; this.adjustingHeight = true;
const animationPromises = []; const animationPromises = [];
console.log("scrolling", heights.before, index)
for (const part in heights) { for (const part in heights) {
const $part = $scrubber.find(`.Scrubber-${part}`); const $part = $scrubber.find(`.Scrubber-${part}`);
animationPromises.push( animationPromises.push(

View File

@@ -166,6 +166,7 @@ class PostStreamState {
loadNearIndex(index) { loadNearIndex(index) {
console.log('loadNearIndex', index); console.log('loadNearIndex', index);
if (index >= this.visibleStart && index <= this.visibleEnd) { if (index >= this.visibleStart && index <= this.visibleEnd) {
console.log("doing the thing")
return m.deferred().resolve().promise; return m.deferred().resolve().promise;
} }