From 1669bdc6bd95ee934041d581141d41937a23dea3 Mon Sep 17 00:00:00 2001 From: Jason Wall Date: Sun, 10 Mar 2024 23:00:54 +0000 Subject: [PATCH] Fix bug where strongs numbers in a strongs definition weren't rendering --- .../strongs/card/strongs-card.component.ts | 2 +- .../modal/strongs-modal.component.html | 26 +++++----- .../strongs/modal/strongs-modal.component.ts | 48 +++++++++++++++---- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/src/app/components/strongs/card/strongs-card.component.ts b/src/src/app/components/strongs/card/strongs-card.component.ts index 442cb027..95b72401 100644 --- a/src/src/app/components/strongs/card/strongs-card.component.ts +++ b/src/src/app/components/strongs/card/strongs-card.component.ts @@ -52,7 +52,7 @@ export class StrongsCardComponent extends CardComponent { if (this.asModal) { const card = await this.appService.getStrongsCard(sn, dict); this.dialog.open(StrongsModalComponent, { - data: card, + data: [card], autoFocus: 'content', }); } else { diff --git a/src/src/app/components/strongs/modal/strongs-modal.component.html b/src/src/app/components/strongs/modal/strongs-modal.component.html index db163e10..ffe2d339 100644 --- a/src/src/app/components/strongs/modal/strongs-modal.component.html +++ b/src/src/app/components/strongs/modal/strongs-modal.component.html @@ -14,19 +14,23 @@ - - - {{ card.prefix }}{{ card.sn }} - - - - + + + + {{ card.prefix }}{{ card.sn }} + + + + + diff --git a/src/src/app/components/strongs/modal/strongs-modal.component.ts b/src/src/app/components/strongs/modal/strongs-modal.component.ts index cd8009cf..b4fa9b81 100644 --- a/src/src/app/components/strongs/modal/strongs-modal.component.ts +++ b/src/src/app/components/strongs/modal/strongs-modal.component.ts @@ -1,7 +1,8 @@ -import { ChangeDetectionStrategy,Component, Inject } from '@angular/core'; -import { MAT_DIALOG_DATA,MatDialogRef } from '@angular/material/dialog'; -import { Observable } from 'rxjs'; +import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; +import { BehaviorSubject, Observable } from 'rxjs'; import { BibleReference } from 'src/app/common/bible-reference'; +import { SubscriberBase } from 'src/app/common/subscriber-base'; import { CardItem } from 'src/app/models/card-state'; import { StrongsResult } from 'src/app/models/strongs-state'; import { AppService } from 'src/app/services/app.service'; @@ -13,25 +14,56 @@ import { AppService } from 'src/app/services/app.service'; preserveWhitespaces: true, changeDetection: ChangeDetectionStrategy.OnPush, }) -export class StrongsModalComponent { +export class StrongsModalComponent extends SubscriberBase { icon$: Observable; - strongsResults: StrongsResult[]; + results$: BehaviorSubject = new BehaviorSubject([]); + selectedIndex = 0; title: string; + asModal = false; constructor( @Inject(MAT_DIALOG_DATA) public cardItems: CardItem[], public dialogRef: MatDialogRef, - private appService: AppService + private appService: AppService, + protected dialog: MatDialog ) { - this.title = cardItems.map(o => o.qry).reduce((p, c) => `${p}, ${c}`); - this.strongsResults = cardItems.map(o => o.data as StrongsResult); + super(); + this.title = cardItems.map((o) => o.qry).reduce((p, c) => `${p}, ${c}`); + this.results$.next(cardItems.map((o) => o.data as StrongsResult)); this.icon$ = appService.select((state) => state.settings.value.cardIcons.strongs); + + this.addSubscription( + this.appService + .select((state) => state.settings.value.displaySettings.showStrongsAsModal) + .subscribe((asModal) => { + this.asModal = asModal; + }) + ); } cancel() { this.dialogRef.close(); } + async openStrongs(q: string) { + const dict = q.substring(0, 1) === 'H' ? 'heb' : 'grk'; + const sn = q.substring(1); + if (this.asModal) { + const currIdx = this.results$.value.findIndex((o) => o.sn.toString() === sn); + if (currIdx > -1) { + this.selectedIndex = currIdx; + return; + } + const card = await this.appService.getStrongsCard(sn, dict); + const strongs = card.data as StrongsResult; + const ordered = [...this.results$.value.filter((o) => `${o.prefix}${o.sn}` !== q), strongs]; + this.results$.next(ordered); + this.selectedIndex = ordered.length - 1; + } else { + this.appService.getStrongs([sn], dict, this.cardItems[0]); + } + } + openPassage(p: string) { const ref = BibleReference.makePassageFromReferenceKey(p); this.appService.getPassage(ref, this.cardItems[0]);