From 915125b796abe03f0bd5933ec59bbf4ce680d23f Mon Sep 17 00:00:00 2001 From: Jason Wall Date: Fri, 1 Mar 2024 21:43:55 +0000 Subject: [PATCH] Bug fixes 4 --- .../components/note/note-card.component.ts | 12 +++++------ src/src/app/pages/search/search.page.html | 1 + src/src/app/pages/search/search.page.ts | 7 ++++++- src/src/app/services/app.service.ts | 3 ++- src/src/app/services/storage.service.ts | 20 +++++++++++-------- src/src/index.html | 9 +-------- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/src/app/components/note/note-card.component.ts b/src/src/app/components/note/note-card.component.ts index e8576c17..2cc5e608 100644 --- a/src/src/app/components/note/note-card.component.ts +++ b/src/src/app/components/note/note-card.component.ts @@ -22,11 +22,7 @@ export class NoteCardComponent extends CardComponent { return this.cardItem.data as NoteItem; } - constructor( - protected elementRef: ElementRef, - protected appService: AppService, - public dialog: MatDialog - ) { + constructor(protected elementRef: ElementRef, protected appService: AppService, public dialog: MatDialog) { super(elementRef, dialog, appService); this.icon$ = appService.select((state) => state.settings.value.cardIcons.note); @@ -38,8 +34,12 @@ export class NoteCardComponent extends CardComponent { this.copyToClip(text, html); } + private xrefs: BibleReference[]; prepXref(xref: string) { - return xref.split(';').map((o) => new BibleReference(o)); + if (this.xrefs === undefined) { + this.xrefs = xref.split(';').map((o) => new BibleReference(o)); + } + return this.xrefs; } openPassage(ref: BibleReference) { diff --git a/src/src/app/pages/search/search.page.html b/src/src/app/pages/search/search.page.html index 9ba70f22..65b00ddc 100644 --- a/src/src/app/pages/search/search.page.html +++ b/src/src/app/pages/search/search.page.html @@ -12,6 +12,7 @@ type="search" autocomplete="off" matInput + #contentView #autoCompleteInput [formControl]="searchControl" [matAutocomplete]="auto" diff --git a/src/src/app/pages/search/search.page.ts b/src/src/app/pages/search/search.page.ts index db83d1ed..26625a6e 100644 --- a/src/src/app/pages/search/search.page.ts +++ b/src/src/app/pages/search/search.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild, ChangeDetectionStrategy } from '@angular/core'; +import { Component, OnInit, ViewChild, ChangeDetectionStrategy, ElementRef } from '@angular/core'; import { ActivatedRoute, Router, NavigationEnd } from '@angular/router'; import { UntypedFormControl } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; @@ -27,9 +27,13 @@ export class SearchPageComponent extends SubscriberBase implements OnInit { @ViewChild(MatAutocomplete) autoComplete: MatAutocomplete; + @ViewChild('autoCompleteInput', { read: MatAutocompleteTrigger }) autoCompleteTrigger: MatAutocompleteTrigger; + @ViewChild('contentView') + contentView: ElementRef; + constructor( private activatedRoute: ActivatedRoute, private appService: AppService, @@ -84,6 +88,7 @@ export class SearchPageComponent extends SubscriberBase implements OnInit { onSavedPagedLoaded(id: string) { if (this.savedPagedLoaded) { this.appService.getSavedPage(id); + this.contentView?.nativeElement?.focus(); return; // you did it! stop trying. } // the saved page hasn't loaded yet, wait then try again. diff --git a/src/src/app/services/app.service.ts b/src/src/app/services/app.service.ts index 4f7371b1..6cb8183d 100644 --- a/src/src/app/services/app.service.ts +++ b/src/src/app/services/app.service.ts @@ -156,7 +156,8 @@ export class AppService extends createStateService(reducer, initialState) { async updateCards(queries: IStorable) { const cards: CardItem[] = []; - for (const q of queries.value) { + const values = queries.value ?? []; + for (const q of values) { const card = await this.getCardByQuery(q.qry.trim(), q.type); cards.push(card); } diff --git a/src/src/app/services/storage.service.ts b/src/src/app/services/storage.service.ts index c60bf39f..ee82a1a1 100644 --- a/src/src/app/services/storage.service.ts +++ b/src/src/app/services/storage.service.ts @@ -122,7 +122,7 @@ export class StorageService extends SubscriberBase { this.savedPagesRemoteObject .valueChanges() // when the value changes .subscribe((remoteData) => { - if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) { + if (!isNullOrUndefined(remoteData)) { // update the app state with remote data if it isn't null // console.log('Data recieved from remote store', remoteData); this.appService.updateSavedPages(remoteData); @@ -135,7 +135,7 @@ export class StorageService extends SubscriberBase { this.noteItemsRemoteObject .valueChanges() // when the value changes .subscribe((remoteData) => { - if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) { + if (!isNullOrUndefined(remoteData)) { // update the app state with remote data if it isn't null // console.log('Data recieved from remote store', remoteData); this.appService.updateNotes(remoteData); @@ -150,7 +150,11 @@ export class StorageService extends SubscriberBase { this.cardsRemoteObject .valueChanges() // when the value changes .subscribe((remoteData) => { - if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value) && this.syncCurrentItems) { + if (!this.syncCurrentItems) { + return; + } + + if (!isNullOrUndefined(remoteData)) { // update the app state with remote data, but only if syncing is turned on. this.appService.updateCards(remoteData); } @@ -285,15 +289,15 @@ export class StorageService extends SubscriberBase { } // update local - this.local.set(this.cardsPath, v.currentCards).subscribe( - () => { + this.local.set(this.cardsPath, v.currentCards).subscribe({ + next: () => { // nop }, // error - () => { + error: () => { this.appService.dispatchError(`Something went wrong and the current cards weren't saved. :(`); - } - ); + }, + }); // since you updated the local variable above, this remote update will // get picked up by the remote subscription below. diff --git a/src/src/index.html b/src/src/index.html index 0f3f9ff9..324c5c80 100644 --- a/src/src/index.html +++ b/src/src/index.html @@ -5,14 +5,7 @@ Dynamic Bible