Don't run some chapter init code when not necessary

This commit is contained in:
Ajay
2022-12-11 15:46:29 -05:00
parent 7eb6b3a79d
commit 3b776991a6

View File

@@ -309,8 +309,6 @@ class PreviewBar {
this.container.appendChild(bar); this.container.appendChild(bar);
} }
console.log(this.segments)
console.trace()
this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0])); this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0]));
if (chapterChevron) { if (chapterChevron) {
@@ -359,7 +357,10 @@ class PreviewBar {
return; return;
} }
if (segments !== this.lastRenderedSegments) { const remakingBar = segments !== this.lastRenderedSegments;
if (remakingBar) {
this.lastRenderedSegments = segments;
// Merge overlapping chapters // Merge overlapping chapters
this.unfilteredChapterGroups = this.createChapterRenderGroups(segments); this.unfilteredChapterGroups = this.createChapterRenderGroups(segments);
} }
@@ -373,9 +374,7 @@ class PreviewBar {
return; return;
} }
if (segments !== this.lastRenderedSegments) { if (remakingBar) {
this.lastRenderedSegments = segments;
const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment)); const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment));
if (filteredSegments) { if (filteredSegments) {
let groups = this.unfilteredChapterGroups; let groups = this.unfilteredChapterGroups;
@@ -453,8 +452,10 @@ class PreviewBar {
} }
} }
if (remakingBar) {
this.updateChapterAllMutation(this.originalChapterBar, this.progressBar, true); this.updateChapterAllMutation(this.originalChapterBar, this.progressBar, true);
} }
}
createChapterRenderGroups(segments: PreviewBarSegment[]): ChapterGroup[] { createChapterRenderGroups(segments: PreviewBarSegment[]): ChapterGroup[] {
const result: ChapterGroup[] = []; const result: ChapterGroup[] = [];