rename cards in preparation for future changes

This commit is contained in:
Jason Wall 2020-08-19 11:01:15 -04:00
parent b37eed2781
commit f2353a5627
5 changed files with 43 additions and 43 deletions

View File

@ -11,7 +11,7 @@ export interface AppState {
readonly displaySettings: IStorable<DisplaySettings>; readonly displaySettings: IStorable<DisplaySettings>;
readonly pageSettings: IStorable<PageSettings>; readonly pageSettings: IStorable<PageSettings>;
readonly savedPagesLoaded: boolean; readonly savedPagesLoaded: boolean;
readonly cards: readonly CardItem[]; readonly currentCards: readonly CardItem[];
readonly autocomplete: readonly string[]; readonly autocomplete: readonly string[];
readonly error: Error; readonly error: Error;
readonly cardIcons: CardIcons; readonly cardIcons: CardIcons;

View File

@ -17,7 +17,7 @@ import { CardItem, CardType } from 'src/app/models/card-state';
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class SearchPage extends SubscriberBase implements OnInit { export class SearchPage extends SubscriberBase implements OnInit {
cards$ = this.appService.select((state) => state.cards); cards$ = this.appService.select((state) => state.currentCards);
suggestions$ = this.appService.select((state) => state.autocomplete); suggestions$ = this.appService.select((state) => state.autocomplete);
savedPagedLoaded = false; savedPagedLoaded = false;

View File

@ -3,7 +3,7 @@ import { Overlap } from '../common/bible-reference';
export const initialState: AppState = { export const initialState: AppState = {
user: null, user: null,
cards: [], currentCards: [],
autocomplete: [], autocomplete: [],
currentSavedPage: null, currentSavedPage: null,
savedPages: null, savedPages: null,

View File

@ -29,7 +29,7 @@ describe('getNewestStorable', () => {
describe('AppService Reducer', () => { describe('AppService Reducer', () => {
const preState = { const preState = {
user: null, user: null,
cards: [], currentCards: [],
autocomplete: [], autocomplete: [],
currentSavedPage: { currentSavedPage: {
queries: [], queries: [],
@ -231,7 +231,7 @@ describe('AppService Reducer', () => {
const action1 = AppActionFactory.newAddCard(card1, null); const action1 = AppActionFactory.newAddCard(card1, null);
const testState = reducer(preState, action1); const testState = reducer(preState, action1);
expect(testState.cards[0]).toBe(card1, 'Failed to add first card to empty list'); expect(testState.currentCards[0]).toBe(card1, 'Failed to add first card to empty list');
const action = AppActionFactory.newUpdateCurrentPage(); const action = AppActionFactory.newUpdateCurrentPage();
const testState2 = reducer(testState, action); const testState2 = reducer(testState, action);
@ -261,7 +261,7 @@ describe('AppService Reducer', () => {
const action1 = AppActionFactory.newAddCard(card1, null); const action1 = AppActionFactory.newAddCard(card1, null);
const testState = reducer(preState, action1); const testState = reducer(preState, action1);
expect(testState.cards[0]).toBe(card1, 'Failed to add first card to empty list'); expect(testState.currentCards[0]).toBe(card1, 'Failed to add first card to empty list');
const card2: CardItem = { const card2: CardItem = {
qry: 'G123', qry: 'G123',
@ -271,8 +271,8 @@ describe('AppService Reducer', () => {
const action2 = AppActionFactory.newAddCard(card2, null); const action2 = AppActionFactory.newAddCard(card2, null);
const testState2 = reducer(testState, action2); const testState2 = reducer(testState, action2);
expect(testState2.cards.length).toBe(2, 'Failed to add second card to list with 1 item'); expect(testState2.currentCards.length).toBe(2, 'Failed to add second card to list with 1 item');
expect(testState2.cards[1]).toBe(card2); expect(testState2.currentCards[1]).toBe(card2);
const card3: CardItem = { const card3: CardItem = {
qry: 'G1234', qry: 'G1234',
@ -304,8 +304,8 @@ describe('AppService Reducer', () => {
const action3 = AppActionFactory.newAddCard(card3, card2); const action3 = AppActionFactory.newAddCard(card3, card2);
const testState3 = reducer(setState, action3); const testState3 = reducer(setState, action3);
expect(testState3.cards.length).toBe(3, 'Failed to add third card'); expect(testState3.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState3.cards[1]).toBe(card3, 'Failed to insert card above the second card'); expect(testState3.currentCards[1]).toBe(card3, 'Failed to insert card above the second card');
// append to bottom, insert next to card // append to bottom, insert next to card
@ -331,8 +331,8 @@ describe('AppService Reducer', () => {
const action4 = AppActionFactory.newAddCard(card3, card1); const action4 = AppActionFactory.newAddCard(card3, card1);
const testState4 = reducer(setState, action4); const testState4 = reducer(setState, action4);
expect(testState4.cards.length).toBe(3, 'Failed to add third card'); expect(testState4.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState4.cards[1]).toBe(card3, 'Failed to insert card below the first card'); expect(testState4.currentCards[1]).toBe(card3, 'Failed to insert card below the first card');
// append to bottom, do not insert next to card // append to bottom, do not insert next to card
@ -358,8 +358,8 @@ describe('AppService Reducer', () => {
const action5 = AppActionFactory.newAddCard(card3, card1); const action5 = AppActionFactory.newAddCard(card3, card1);
const testState5 = reducer(setState, action5); const testState5 = reducer(setState, action5);
expect(testState5.cards.length).toBe(3, 'Failed to add third card'); expect(testState5.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState5.cards[2]).toBe(card3, 'Failed to insert card at end of the list'); expect(testState5.currentCards[2]).toBe(card3, 'Failed to insert card at end of the list');
// append to top, do not insert next to card // append to top, do not insert next to card
@ -385,8 +385,8 @@ describe('AppService Reducer', () => {
const action6 = AppActionFactory.newAddCard(card3, card1); const action6 = AppActionFactory.newAddCard(card3, card1);
const testState6 = reducer(setState, action6); const testState6 = reducer(setState, action6);
expect(testState6.cards.length).toBe(3, 'Failed to add third card'); expect(testState6.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState6.cards[0]).toBe(card3, 'Failed to insert card at start of the list'); expect(testState6.currentCards[0]).toBe(card3, 'Failed to insert card at start of the list');
}); });
// 'UPDATE_CARD'; // 'UPDATE_CARD';

View File

@ -126,7 +126,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
...state, ...state,
// if the currentSavedPage was loaded, replace it with the info from the // if the currentSavedPage was loaded, replace it with the info from the
// new savedPages array, as it might have changed. // new savedPages array, as it might have changed.
cards: hasCurrentSavedPage ? currentSavedPage.queries : state.cards, currentCards: hasCurrentSavedPage ? currentSavedPage.queries : state.currentCards,
currentSavedPage: hasCurrentSavedPage ? currentSavedPage : state.currentSavedPage, currentSavedPage: hasCurrentSavedPage ? currentSavedPage : state.currentSavedPage,
savedPagesLoaded: true, savedPagesLoaded: true,
savedPages, // update the savedPages savedPages, // update the savedPages
@ -159,7 +159,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
const current = { const current = {
id: state.currentSavedPage.id, id: state.currentSavedPage.id,
title: state.currentSavedPage.title, title: state.currentSavedPage.title,
queries: [...mergeCardList(state.cards, state.pageSettings.value.mergeStrategy)], queries: [...mergeCardList(state.currentCards, state.pageSettings.value.mergeStrategy)],
}; };
const savedPages = new Storable<SavedPage[]>([ const savedPages = new Storable<SavedPage[]>([
@ -182,7 +182,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// create a new saved page object // create a new saved page object
title: action.title, title: action.title,
id: UUID.UUID().toString(), id: UUID.UUID().toString(),
queries: [...mergeCardList(state.cards, state.pageSettings.value.mergeStrategy)], queries: [...mergeCardList(state.currentCards, state.pageSettings.value.mergeStrategy)],
}, },
]); ]);
@ -201,7 +201,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
return { return {
...state, ...state,
currentSavedPage: page, currentSavedPage: page,
cards: [...page.queries], currentCards: [...page.queries],
}; };
} }
case 'MOVE_SAVED_PAGE_CARD': { case 'MOVE_SAVED_PAGE_CARD': {
@ -246,33 +246,33 @@ export function reducer(state: AppState, action: AppAction): AppState {
let cards = []; let cards = [];
if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) { if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) {
const idx = state.cards.indexOf(action.nextToItem); const idx = state.currentCards.indexOf(action.nextToItem);
if (state.displaySettings.value.appendCardToBottom) { if (state.displaySettings.value.appendCardToBottom) {
const before = state.cards.slice(0, idx + 1); const before = state.currentCards.slice(0, idx + 1);
const after = state.cards.slice(idx + 1); const after = state.currentCards.slice(idx + 1);
cards = [...before, action.card, ...after]; cards = [...before, action.card, ...after];
} else { } else {
const before = state.cards.slice(0, idx); const before = state.currentCards.slice(0, idx);
const after = state.cards.slice(idx); const after = state.currentCards.slice(idx);
cards = [...before, action.card, ...after]; cards = [...before, action.card, ...after];
} }
} else { } else {
if (state.displaySettings.value.appendCardToBottom) { if (state.displaySettings.value.appendCardToBottom) {
cards = [...state.cards, action.card]; cards = [...state.currentCards, action.card];
} else { } else {
cards = [action.card, ...state.cards]; cards = [action.card, ...state.currentCards];
} }
} }
return { return {
...state, ...state,
cards, currentCards: cards,
}; };
} }
case 'UPDATE_CARD': { case 'UPDATE_CARD': {
return { return {
...state, ...state,
cards: state.cards.map((c) => { currentCards: state.currentCards.map((c) => {
if (c === action.oldCard) { if (c === action.oldCard) {
return action.newCard; return action.newCard;
} }
@ -306,15 +306,15 @@ export function reducer(state: AppState, action: AppAction): AppState {
...state, ...state,
currentSavedPage, currentSavedPage,
savedPages, savedPages,
cards: [...state.cards.filter((c) => c !== action.card)], currentCards: [...state.currentCards.filter((c) => c !== action.card)],
}; };
} }
case 'MOVE_CARD': { case 'MOVE_CARD': {
const cards = moveItemUpOrDown(state.cards, action.card, action.direction); const cards = moveItemUpOrDown(state.currentCards, action.card, action.direction);
return { return {
...state, ...state,
cards, currentCards: cards,
}; };
} }
@ -343,27 +343,27 @@ export function reducer(state: AppState, action: AppAction): AppState {
let cards = [] as CardItem[]; let cards = [] as CardItem[];
if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) { if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) {
const idx = state.cards.indexOf(action.nextToItem); const idx = state.currentCards.indexOf(action.nextToItem);
if (state.displaySettings.value.appendCardToBottom) { if (state.displaySettings.value.appendCardToBottom) {
const before = state.cards.slice(0, idx + 1); const before = state.currentCards.slice(0, idx + 1);
const after = state.cards.slice(idx + 1); const after = state.currentCards.slice(idx + 1);
cards = [...before, ...notes, ...after]; cards = [...before, ...notes, ...after];
} else { } else {
const before = state.cards.slice(0, idx); const before = state.currentCards.slice(0, idx);
const after = state.cards.slice(idx); const after = state.currentCards.slice(idx);
cards = [...before, ...notes, ...after]; cards = [...before, ...notes, ...after];
} }
} else { } else {
if (state.displaySettings.value.appendCardToBottom) { if (state.displaySettings.value.appendCardToBottom) {
cards = [...state.cards, ...notes]; cards = [...state.currentCards, ...notes];
} else { } else {
cards = [...notes, ...state.cards]; cards = [...notes, ...state.currentCards];
} }
} }
return { return {
...state, ...state,
cards, currentCards: cards,
}; };
} }
case 'GET_NOTE': { case 'GET_NOTE': {
@ -396,7 +396,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// in any of them, swap it out // in any of them, swap it out
const cards = [ const cards = [
...state.cards.map((o) => { ...state.currentCards.map((o) => {
const n = o.data as NoteItem; const n = o.data as NoteItem;
if (n && n.id === action.note.id) { if (n && n.id === action.note.id) {
return { return {
@ -447,7 +447,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// in any of them, remove it // in any of them, remove it
const cards = [ const cards = [
...state.cards.filter((o) => { ...state.currentCards.filter((o) => {
const n = o.data as NoteItem; const n = o.data as NoteItem;
return !n || n.id !== action.note.id; return !n || n.id !== action.note.id;
}), }),
@ -468,7 +468,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
]); ]);
return { return {
...state, ...state,
cards, currentCards: cards,
notes, notes,
savedPages, savedPages,
}; };