From 70cdb6b3b0b22ccf1e905cca0ec04b79303ff36a Mon Sep 17 00:00:00 2001 From: isark Date: Sat, 25 Nov 2023 14:03:51 +0100 Subject: [PATCH] Fixed some plan loading init issues --- src-tauri/tauri.conf.json | 2 +- src/app/carousel/carousel.component.ts | 34 ++++++++++++------- .../plan-display/plan-display.component.ts | 13 +++++-- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5c23d0c..c0fb379 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Nothing", - "version": "1.1.0" + "version": "1.1.1" }, "tauri": { "systemTray": { diff --git a/src/app/carousel/carousel.component.ts b/src/app/carousel/carousel.component.ts index 0fbd1e3..8089873 100644 --- a/src/app/carousel/carousel.component.ts +++ b/src/app/carousel/carousel.component.ts @@ -135,13 +135,20 @@ export class CarouselComponent implements OnInit, AfterViewInit { setIndex(slideIndex: number) { this.current = slideIndex; - - for (let i = Math.max(-this.numExtraPrev(), 0); i <= Math.min(this.numExtraNext(), this.slides!.length - 1); i++) { - this.visibleSlides?.push({ - index: this.current + i, - hasBeenVisible: false, - currentlyIntersecting: false, - }); + console.log("setIndex", slideIndex); + this.visibleSlides!.length = 0; + console.log("length", this.slides!.length); + + for (let i = -this.numExtraPrev(); i <= this.numExtraNext(); i++) { + console.log("i, ", i); + if (this.current + i >= 0 && this.current + i < this.slides!.length) { + console.log("pushing", this.current + i); + this.visibleSlides?.push({ + index: this.current + i, + hasBeenVisible: false, + currentlyIntersecting: false, + }); + } } this.onChange(); @@ -192,15 +199,18 @@ export class CarouselComponent implements OnInit, AfterViewInit { const safetyFactor = this.numVisible == 1 ? 1 : 2; { const intersecting = this.visibleSlides?.filter(e => e.currentlyIntersecting).sort((e1, e2) => e1.index - e2.index); - const lowestIntersecting = intersecting![0]; - this.visibleSlides = this.visibleSlides?.filter(e => e.index + safetyFactor >= lowestIntersecting!.index && e.index >= this.current - this.numExtraPrev()); - + if (intersecting && intersecting.length > 0) { + const lowestIntersecting = intersecting![0]; + this.visibleSlides = this.visibleSlides?.filter(e => e.index + safetyFactor >= lowestIntersecting!.index && e.index >= this.current - this.numExtraPrev()); + } } { const intersecting = this.visibleSlides?.filter(e => e.currentlyIntersecting).sort((e1, e2) => e1.index - e2.index).reverse(); - const highestIntersecting = intersecting![0] - this.visibleSlides = this.visibleSlides?.filter(e => e.index - safetyFactor <= highestIntersecting!.index && e.index <= this.current + this.numExtraNext()); + if (intersecting && intersecting.length > 0) { + const highestIntersecting = intersecting![0] + this.visibleSlides = this.visibleSlides?.filter(e => e.index - safetyFactor <= highestIntersecting!.index && e.index <= this.current + this.numExtraNext()); + } } } diff --git a/src/app/plan-display/plan-display.component.ts b/src/app/plan-display/plan-display.component.ts index c1ee05e..abe3160 100644 --- a/src/app/plan-display/plan-display.component.ts +++ b/src/app/plan-display/plan-display.component.ts @@ -200,17 +200,18 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { setIndex(index: number) { this.slideIndex = index; if (this.currentSlides) { - this.currentSlides.current = index; + this.currentSlides.setIndex(index); } if (this.zoneSlides) { - this.zoneSlides.current = index; + this.zoneSlides.setIndex(index); + } } setPrevious(plan: string) { this.planService.loadPrevious(plan).subscribe(plan => { - this.setIndex(plan.current); + setTimeout(() => this.setIndex(plan.current), 0); }); } @@ -267,6 +268,12 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { loadBasePlan() { this.planService.loadBasePlan().subscribe(plan => { this.planService.currentPlan = new Plan(plan); + if (this.zoneSlides) { + this.zoneSlides.setIndex(0); + } + if (this.currentSlides) { + this.currentSlides.setIndex(0); + } }) }