mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-23 07:19:50 -04:00
Bug fixes
This commit is contained in:
parent
c1544f79b2
commit
f83a4f5d48
@ -49,8 +49,8 @@ export class PassageCardComponent extends CardComponent implements OnInit {
|
||||
}
|
||||
|
||||
copy() {
|
||||
const html = this.passageElement.nativeElement.innerHTML;
|
||||
const text = this.passageElement.nativeElement.innerText;
|
||||
const html = this.passageElement.nativeElement.innerHTML + ` - ${this.ref.toString()}`;
|
||||
const text = this.passageElement.nativeElement.innerText + ` - ${this.ref.toString()}`;
|
||||
this.copyToClip(text, html);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ export class StrongsCardComponent extends CardComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
ngOnInit(): void {
|
||||
console.log(this.cardItem);
|
||||
// console.log(this.cardItem);
|
||||
}
|
||||
|
||||
copy() {
|
||||
|
@ -1,12 +1,31 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { reducer } from './app-state-reducer';
|
||||
import { AppAction, AppActionFactory } from './app-state-actions';
|
||||
import { reducer, getNewestStorable } from './app-state-reducer';
|
||||
import { AppActionFactory } from './app-state-actions';
|
||||
import { Overlap } from '../common/bible-reference';
|
||||
import { IStorable, Storable } from '../common/storable';
|
||||
import { CardType, CardIcons, CardItem } from '../models/card-state';
|
||||
import { Storable } from '../common/storable';
|
||||
import { CardType, CardItem } from '../models/card-state';
|
||||
import { SavedPage } from '../models/page-state';
|
||||
import { AppState } from '../models/app-state';
|
||||
|
||||
describe('getNewestStorable', () => {
|
||||
it('maybeMutateStorable', () => {
|
||||
const s1 = {
|
||||
createdOn: new Date(2019, 1, 1, 0, 0, 0, 0).toISOString(),
|
||||
value: 'test1',
|
||||
};
|
||||
|
||||
const s2 = {
|
||||
createdOn: new Date(2020, 1, 1, 0, 0, 0, 0).toISOString(),
|
||||
value: 'test1',
|
||||
};
|
||||
|
||||
expect(getNewestStorable(s1, s2)).toBe(s2, 'Should be the second item');
|
||||
expect(getNewestStorable(null, s2)).toBe(s2, 'Should be the second item');
|
||||
expect(getNewestStorable(s1, null)).toBe(s1, 'Should be the first item');
|
||||
expect(getNewestStorable(null, null)).toBe(null, 'Should be null');
|
||||
});
|
||||
});
|
||||
|
||||
describe('AppService Reducer', () => {
|
||||
const preState = {
|
||||
user: null,
|
||||
|
@ -12,29 +12,19 @@ import { initialState } from './app-state-initial-state';
|
||||
import { SavedPage } from '../models/page-state';
|
||||
import { CardType, CardItem } from '../models/card-state';
|
||||
|
||||
function maybeMutateStorable<T>(
|
||||
state: AppState,
|
||||
candidate: IStorable<T>,
|
||||
incumbant: IStorable<T>,
|
||||
composeState: (item: IStorable<T>) => AppState
|
||||
): AppState {
|
||||
export function getNewestStorable<T>(candidate: IStorable<T>, incumbant: IStorable<T>): IStorable<T> {
|
||||
// if the candidate is null, then return the state.
|
||||
if (!candidate) {
|
||||
return state;
|
||||
}
|
||||
|
||||
// if the incumbant is null, then def use the candidate.
|
||||
if (!incumbant) {
|
||||
return composeState(candidate);
|
||||
return incumbant;
|
||||
}
|
||||
|
||||
// only update if the settings are newer.
|
||||
if (!incumbant || new Date(candidate.createdOn) > new Date(incumbant.createdOn)) {
|
||||
return composeState(candidate);
|
||||
return candidate;
|
||||
}
|
||||
|
||||
// candidate didn't win. return state untouched.
|
||||
return state;
|
||||
return incumbant;
|
||||
}
|
||||
|
||||
export function reducer(state: AppState, action: AppAction): AppState {
|
||||
@ -44,6 +34,13 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case 'UPDATE_ERROR': {
|
||||
return {
|
||||
...state,
|
||||
error: action.error,
|
||||
};
|
||||
}
|
||||
|
||||
//#region Saved Page Settings
|
||||
|
||||
case 'UPDATE_CARD_MERGE_STRATEGY': {
|
||||
@ -58,12 +55,11 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
}
|
||||
|
||||
case 'UPDATE_PAGE_SETTINGS': {
|
||||
return maybeMutateStorable(state, action.settings, state.pageSettings, (item) => {
|
||||
return {
|
||||
...state,
|
||||
pageSettings: item,
|
||||
};
|
||||
});
|
||||
const item = getNewestStorable(action.settings, state.pageSettings);
|
||||
return {
|
||||
...state,
|
||||
pageSettings: item,
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@ -71,12 +67,12 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
//#region Display Settings
|
||||
|
||||
case 'UPDATE_DISPLAY_SETTINGS': {
|
||||
return maybeMutateStorable(state, action.settings, state.displaySettings, (item) => {
|
||||
return {
|
||||
...state,
|
||||
displaySettings: item,
|
||||
};
|
||||
});
|
||||
const item = getNewestStorable(action.settings, state.displaySettings);
|
||||
|
||||
return {
|
||||
...state,
|
||||
displaySettings: item,
|
||||
};
|
||||
}
|
||||
case 'UPDATE_CARD_FONT_SIZE': {
|
||||
const settings = new Storable<DisplaySettings>({
|
||||
@ -110,13 +106,13 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
};
|
||||
}
|
||||
case 'UPDATE_SAVED_PAGES': {
|
||||
return maybeMutateStorable(state, action.savedPages, state.savedPages, (item) => {
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
});
|
||||
const item = getNewestStorable(action.savedPages, state.savedPages);
|
||||
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
}
|
||||
case 'UPDATE_SAVED_PAGE': {
|
||||
const savedPages = new Storable<SavedPage[]>(
|
||||
@ -128,24 +124,22 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
})
|
||||
);
|
||||
|
||||
return maybeMutateStorable(state, savedPages, state.savedPages, (item) => {
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
});
|
||||
const item = getNewestStorable(savedPages, state.savedPages);
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
}
|
||||
case 'REMOVE_SAVED_PAGE': {
|
||||
const savedPages = new Storable<SavedPage[]>(state.savedPages.value.filter((o) => o.id !== action.savedPage.id));
|
||||
const item = getNewestStorable(savedPages, state.savedPages);
|
||||
|
||||
return maybeMutateStorable(state, savedPages, state.savedPages, (item) => {
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
});
|
||||
return {
|
||||
...state,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
}
|
||||
case 'UPDATE_CURRENT_PAGE': {
|
||||
const current = {
|
||||
@ -159,14 +153,13 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
current,
|
||||
]);
|
||||
|
||||
return maybeMutateStorable(state, savedPages, state.savedPages, (item) => {
|
||||
return {
|
||||
...state,
|
||||
currentSavedPage: current,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
});
|
||||
const item = getNewestStorable(savedPages, state.savedPages);
|
||||
return {
|
||||
...state,
|
||||
currentSavedPage: current,
|
||||
savedPagesLoaded: true,
|
||||
savedPages: item,
|
||||
};
|
||||
}
|
||||
case 'SAVE_PAGE': {
|
||||
const savedPages = new Storable([
|
||||
|
@ -401,12 +401,13 @@ export class AppService extends createStateService(reducer, initialState) {
|
||||
if (j + 1 === chapters.length) {
|
||||
end = section.end.verse;
|
||||
} else {
|
||||
end = '*';
|
||||
// go to the end of the chapter
|
||||
end = chapters[j].vss.length;
|
||||
}
|
||||
|
||||
// get the verses requested.
|
||||
const tvs = chapters[j].vss.length;
|
||||
if (end === 0 || end > tvs) {
|
||||
if (end === 0) {
|
||||
end = tvs;
|
||||
}
|
||||
|
||||
@ -843,6 +844,7 @@ export class AppService extends createStateService(reducer, initialState) {
|
||||
// tslint:disable-next-line: prefer-for-of
|
||||
for (let j = 0; j < referenceSet.length; j++) {
|
||||
const refs = referenceSet[j];
|
||||
results[j] = []; // initialize inner array
|
||||
if (refs != null) {
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
const r = refs[i].split(':');
|
||||
|
Loading…
x
Reference in New Issue
Block a user