CardTypes are now an enum

This commit is contained in:
Jeremy Wall 2020-08-09 09:42:20 -04:00
parent bafd755134
commit 6c8d01d9b8
5 changed files with 36 additions and 28 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

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

View File

@ -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,
};