Skip to content

Commit 0b6c088

Browse files
committed
Merge branch 'master' into chapter-scroll-other-users
2 parents 3b63ef3 + 8070aef commit 0b6c088

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

ui/analyse/src/study/studyChapters.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,15 @@ export function view(ctrl: StudyCtrl): VNode {
230230
}
231231

232232
export class StudyChapterScroller {
233-
constructor(
234-
public request: ScrollBehavior | undefined = 'instant',
235-
public rafId?: number,
236-
) {}
233+
request: Prop<ScrollBehavior | null> = prop('instant');
234+
private rafId?: number;
237235

238236
scrollIfNeeded(list: HTMLElement) {
239-
if (!this.request) return;
237+
const request = this.request();
238+
if (!request) return;
240239
const active = list.querySelector('.active');
241240
if (!active) return;
242-
const request = this.request;
243-
this.request = undefined;
241+
this.request(null);
244242
const [c, l] = [list.getBoundingClientRect(), active.getBoundingClientRect()];
245243
if (c.top < l.top || c.bottom > l.bottom) {
246244
cancelAnimationFrame(this.rafId ?? 0);

ui/analyse/src/study/studyCtrl.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export default class StudyCtrl {
269269
};
270270

271271
setTab = (tab: Tab) => {
272-
if (tab === 'chapters') this.chapters.scroller.request = 'instant';
272+
if (tab === 'chapters') this.chapters.scroller.request('instant');
273273
this.vm.tab(tab);
274274
this.redraw();
275275
};
@@ -492,6 +492,7 @@ export default class StudyCtrl {
492492
this.redraw();
493493
return true;
494494
}
495+
this.chapters.scroller.request('smooth');
495496
this.vm.nextChapterId = id;
496497
this.vm.justSetChapterId = id;
497498
if (this.vm.mode.sticky && this.makeChange('setChapter', id)) {
@@ -505,7 +506,7 @@ export default class StudyCtrl {
505506
this.vm.mode.sticky = false;
506507
if (!this.vm.behind) this.vm.behind = 1;
507508
this.vm.chapterId = id;
508-
this.chapters.scroller.request = 'smooth'; // sticky scroll request is set in `changeChapter`
509+
this.chapters.scroller.request('smooth'); // sticky scroll request is set in `changeChapter`
509510
this.relay?.liveboardPlugin?.reset();
510511
await this.xhrReload(false, () => componentCallbacks(id));
511512
}
@@ -741,7 +742,7 @@ export default class StudyCtrl {
741742
this.setMemberActive(d.w);
742743
this.data.position = d.p;
743744
if (this.vm.mode.sticky) {
744-
this.chapters.scroller.request = 'smooth'; // non-sticky scroll request is set in `setChapter`
745+
this.chapters.scroller.request('smooth'); // non-sticky scroll request is set in `setChapter`
745746
this.xhrReload();
746747
} else {
747748
this.vm.behind++;
@@ -781,8 +782,8 @@ export default class StudyCtrl {
781782
this.vm.mode.write = this.relay ? this.relayRecProp() : this.nonRelayRecMapProp(this.data.id);
782783
this.vm.chapterId = d.p.chapterId;
783784
this.vm.nextChapterId = d.p.chapterId;
784-
this.chapters.scroller.request = 'instant';
785-
} else this.chapters.scroller.request = 'smooth';
785+
this.chapters.scroller.request('instant');
786+
} else this.chapters.scroller.request('smooth');
786787
this.xhrReload(true);
787788
},
788789
members: d => {

0 commit comments

Comments
 (0)