diff --git a/app/db/src/app/common/card-operations.spec.ts b/app/db/src/app/common/card-operations.spec.ts index 54f957e7..0c98662b 100644 --- a/app/db/src/app/common/card-operations.spec.ts +++ b/app/db/src/app/common/card-operations.spec.ts @@ -1,11 +1,12 @@ import { maybeMergeCards, mergeCardList } from './card-operations'; import { BibleReference, Overlap } from './bible-reference'; +import { CardType } from '../models/app-state'; describe('Card Merging', () => { it('Should merge two equal cards', () => { let cardList = [ - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, ]; for (const strat of [Overlap.Equal, Overlap.Subset]) { let merged = mergeCardList(cardList, strat); @@ -16,9 +17,9 @@ describe('Card Merging', () => { it('Should merge two equal cards with one in the middle', () => { let cardList = [ - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:2', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:2', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, ]; for (const strat of [Overlap.Equal, Overlap.Subset]) { let merged = mergeCardList(cardList, strat); @@ -30,8 +31,8 @@ describe('Card Merging', () => { it('Should merge two intersecting cards', () => { let cardList = [ - { type: 'Passage', qry: 'Genesis 1:1-2', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1-2', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, ]; for (const strat of [Overlap.Intersect, Overlap.Subset]) { let merged = mergeCardList(cardList, strat); @@ -42,9 +43,9 @@ describe('Card Merging', () => { it('Should merge two intersecting cards with one in the middle', () => { let cardList = [ - { type: 'Passage', qry: 'Genesis 1:1-2', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:4', data: null, dict: '' }, - { type: 'Passage', qry: 'Genesis 1:1', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1-2', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:4', data: null, dict: '' }, + { type: CardType.Passage, qry: 'Genesis 1:1', data: null, dict: '' }, ]; for (const strat of [Overlap.Intersect, Overlap.Subset]) { let merged = mergeCardList(cardList, strat); diff --git a/app/db/src/app/common/card-operations.ts b/app/db/src/app/common/card-operations.ts index fcc4a4cd..defcd701 100644 --- a/app/db/src/app/common/card-operations.ts +++ b/app/db/src/app/common/card-operations.ts @@ -1,5 +1,5 @@ import { BibleReference, Overlap } from './bible-reference'; -import { CardItem } from '../models/app-state'; +import { CardItem, CardType } from '../models/app-state'; export function maybeMergeCards(leftCard: CardItem, rightCard: CardItem, strategy: Overlap): CardItem | null { if (leftCard.type === rightCard.type) { @@ -11,7 +11,7 @@ export function maybeMergeCards(leftCard: CardItem, rightCard: CardItem, strateg break; case Overlap.Intersect: case Overlap.Subset: - if (leftCard.type === 'Passage') { + if (leftCard.type === CardType.Passage) { const leftRef = new BibleReference(leftCard.qry); const rightRef = new BibleReference(rightCard.qry); let mergedRef = BibleReference.mergeReference(leftRef, rightRef, strategy); diff --git a/app/db/src/app/models/app-state.ts b/app/db/src/app/models/app-state.ts index 09b0724c..f265dd24 100644 --- a/app/db/src/app/models/app-state.ts +++ b/app/db/src/app/models/app-state.ts @@ -75,11 +75,18 @@ export interface SavedPage { readonly id: string; } +export enum CardType { + Passage, + Note, + Word, + Strongs, + Error, +} + export interface CardItem { readonly qry: string; readonly data: Data; - // TODO(jwall): This should probably be an enum - readonly type: string; + readonly type: CardType; readonly dict: string; } diff --git a/app/db/src/app/search/components/search-page/search.page.ts b/app/db/src/app/search/components/search-page/search.page.ts index 277ebe38..8ab17157 100644 --- a/app/db/src/app/search/components/search-page/search.page.ts +++ b/app/db/src/app/search/components/search-page/search.page.ts @@ -4,7 +4,7 @@ import { FormControl } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { AppService } from '../../../services/app.service'; import { NavService } from '../../../services/nav.service'; -import { OpenData, CardItem } from '../../../models/app-state'; +import { OpenData, CardItem, CardType } from '../../../models/app-state'; import { BibleReference } from '../../../common/bible-reference'; import { VersePickerModalComponent } from '../verse-picker-modal/verse-picker-modal.component'; import { SubscriberComponent } from '../../../common/components/subscriber.component'; @@ -143,19 +143,19 @@ export class SearchPage extends SubscriberComponent implements OnInit { } isError(t: CardItem) { - return t.type === 'Error'; + return t.type === CardType.Error; } isPassage(t: CardItem) { - return t.type === 'Passage'; + return t.type === CardType.Passage; } isNote(t: CardItem) { - return t.type === 'Note'; + return t.type === CardType.Note; } isStrongs(t: CardItem) { - return t.type === 'Strongs'; + return t.type === CardType.Strongs; } isWords(t: CardItem) { - return t.type === 'Words'; + return t.type === CardType.Word; } //#endregion diff --git a/app/db/src/app/services/app.service.ts b/app/db/src/app/services/app.service.ts index 06b2492e..f463e663 100644 --- a/app/db/src/app/services/app.service.ts +++ b/app/db/src/app/services/app.service.ts @@ -1,6 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { AppState, SavedPage, Error, CardItem, DisplaySettings, User } from '../models/app-state'; +import { AppState, SavedPage, Error, CardItem, DisplaySettings, User, CardType } from '../models/app-state'; import { Section, BibleReference, Overlap } from '../common/bible-reference'; import { PageTitles, PageIcons } from '../constants'; import { createStateService } from '../common/state-service'; @@ -27,7 +27,7 @@ const initialState: AppState = { { qry: 'UUIDGOESHERE', dict: 'n/a', - type: 'Note', + type: CardType.Note, data: { id: UUID.UUID(), xref: '1 pe 2:16; jn 3:16', @@ -396,12 +396,12 @@ function reducer(state: AppState, action: AppAction): AppState { return { qry: o.id, dict: 'n/a', - type: 'Note', + type: CardType.Note, data: o, }; }); - let cards = []; + let cards = [] as CardItem[]; if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) { const idx = state.cards.indexOf(action.nextToItem); @@ -432,7 +432,7 @@ function reducer(state: AppState, action: AppAction): AppState { const card = { qry: note.id, dict: 'n/a', - type: 'Note', + type: CardType.Note, data: note, }; @@ -713,7 +713,7 @@ export class AppService extends createStateService(reducer, initialState) { const card = { qry: `${d}${strongsNumber}`, dict: d, - type: 'Strongs', + type: CardType.Word, data: result, }; return card; @@ -831,7 +831,7 @@ export class AppService extends createStateService(reducer, initialState) { return { qry: ref.toString(), dict: ref.section.book.bookNumber > 39 ? 'G' : 'H', - type: 'Passage', + type: CardType.Passage, data: result, }; } @@ -995,7 +995,7 @@ export class AppService extends createStateService(reducer, initialState) { const card = { qry, dict: 'n/a', - type: 'Words', + type: CardType.Word, data: result, };