Fix bug where strongs numbers in a strongs definition weren't rendering

This commit is contained in:
Jason Wall 2024-03-10 23:00:54 +00:00
parent dace1e3f61
commit 1669bdc6bd
3 changed files with 56 additions and 20 deletions

View File

@ -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 {

View File

@ -14,19 +14,23 @@
</span>
</mat-toolbar>
<mat-dialog-content class="content">
<mat-tab-group *ngIf="strongsResults.length > 1">
<mat-tab *ngFor="let card of strongsResults">
<ng-container *ngIf="(results$ | async).length > 1; let strongs">
<mat-tab-group [(selectedIndex)]="selectedIndex">
<mat-tab *ngFor="let card of results$ | async; index as idx">
<ng-template mat-tab-label>{{ card.prefix }}{{ card.sn }}</ng-template>
<app-strongs
[data]="card"
(openPassage)="openPassage($event)"
(openStrongs)="openStrongs($event)"
></app-strongs>
</mat-tab>
</mat-tab-group>
<ng-container *ngIf="strongsResults.length === 1">
</ng-container>
<ng-container *ngIf="(results$ | async).length === 1">
<app-strongs
[data]="strongsResults[0]"
[data]="(results$ | async)[0]"
(openPassage)="openPassage($event)"
(openStrongs)="openStrongs($event)"
></app-strongs>
</ng-container>
</mat-dialog-content>

View File

@ -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<string>;
strongsResults: StrongsResult[];
results$: BehaviorSubject<StrongsResult[]> = new BehaviorSubject([]);
selectedIndex = 0;
title: string;
asModal = false;
constructor(
@Inject(MAT_DIALOG_DATA) public cardItems: CardItem[],
public dialogRef: MatDialogRef<StrongsModalComponent>,
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]);