From 4b25c1886436436d392dabb3571e3511924fefdf Mon Sep 17 00:00:00 2001 From: smuddyx Date: Sun, 26 Mar 2023 23:53:59 +0200 Subject: [PATCH] fix change detection on push --- .../components/card/card.component.less | 1 + .../song-text/song-text.component.ts | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/app/widget-modules/components/card/card.component.less b/src/app/widget-modules/components/card/card.component.less index f7f0386..605a019 100644 --- a/src/app/widget-modules/components/card/card.component.less +++ b/src/app/widget-modules/components/card/card.component.less @@ -15,6 +15,7 @@ border-radius: 0; background: #ffff; margin: 0; + color: #000; } &.padding { diff --git a/src/app/widget-modules/components/song-text/song-text.component.ts b/src/app/widget-modules/components/song-text/song-text.component.ts index 09b7846..31e424e 100644 --- a/src/app/widget-modules/components/song-text/song-text.component.ts +++ b/src/app/widget-modules/components/song-text/song-text.component.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef, EventEmitter, Input, OnInit, Output, QueryList, ViewChildren} from '@angular/core'; +import {ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnInit, Output, QueryList, ViewChildren} from '@angular/core'; import {TextRenderingService} from '../../../modules/songs/services/text-rendering.service'; import {faGripLines} from '@fortawesome/free-solid-svg-icons'; import {songSwitch} from './animation'; @@ -30,7 +30,7 @@ export class SongTextComponent implements OnInit { private iText = ''; private iTranspose: TransposeMode | null = null; - public constructor(private textRenderingService: TextRenderingService, private elRef: ElementRef) {} + public constructor(private textRenderingService: TextRenderingService, private elRef: ElementRef, private cRef: ChangeDetectorRef) {} @Input() public set chordMode(value: ChordMode) { @@ -49,26 +49,32 @@ export class SongTextComponent implements OnInit { this.render(); } - private render() { - this.offset = 0; - this.sections = []; - if (this.fullscreen) { - setTimeout(() => (this.sections = this.textRenderingService.parse(this.iText, this.iTranspose)), 100); - } else { - this.sections = this.textRenderingService.parse(this.iText, this.iTranspose); //.sort((a, b) => a.type - b.type); - } - } - public ngOnInit(): void { setInterval(() => { if (!this.fullscreen || this.index === -1 || !this.viewSections?.toArray()[this.index]) { this.offset = 0; + this.cRef.markForCheck(); return; } this.offset = -this.viewSections?.toArray()[this.index].nativeElement.offsetTop; + this.cRef.markForCheck(); }, 100); } + private render() { + this.offset = 0; + this.sections = []; + if (this.fullscreen) { + setTimeout(() => { + this.sections = this.textRenderingService.parse(this.iText, this.iTranspose); + this.cRef.markForCheck(); + }, 100); + } else { + this.sections = this.textRenderingService.parse(this.iText, this.iTranspose); //.sort((a, b) => a.type - b.type); + this.cRef.markForCheck(); + } + } + public getLines(section: Section): Line[] { return section.lines.filter(_ => { if (_.type !== LineType.chord) {